Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
mockito-kotlin
Keisuke Kobayashi
December 15, 2017
Programming
1
430
mockito-kotlin
Android Test Night #2
Keisuke Kobayashi
December 15, 2017
Tweet
Share
More Decks by Keisuke Kobayashi
See All by Keisuke Kobayashi
今日から始める依存性の注入 / First Time Dependency Injection
kobakei
26
6.3k
iOSアプリの技術的負債をどう返済したか / How to repay the technical debt of iOS app
kobakei
2
760
iOSアプリ内で不正なSSL証明書を検知する / SSL Pinning for iOS apps
kobakei
33
8.4k
Kyashアプリ開発の現場
kobakei
4
2.2k
Review of Google I/O 2017 & Prepare for Google I/O 2018
kobakei
0
260
APIクライアントをCodableで置き換えた話
kobakei
0
1.2k
開発者が知っておきたい通知の歴史
kobakei
10
6.5k
2017年に新規アプリを立ち上げた話
kobakei
2
840
Everything of CI/CD in Kyash Android
kobakei
0
1.3k
Other Decks in Programming
See All in Programming
io22 extended What's new in app performance
veronikapj
0
320
How we run a Realtime Puzzle Fighting Game on AWS Serverless
falken
0
240
Overview of The Modern Data Stack / モダンデータスタック概論
satoshihirose
6
3.2k
Why Airflow? & What's new in Airflow 2.3?
kaxil
0
110
Modern Android Developer ~ 안내서
pluu
1
570
IE Graduation Certificate
jxck
6
4.7k
Terraform Plan/Apply結果の自動通知
ymmy02
0
270
Maintaining Software Correctness
dlew
PRO
3
230
ISUCON12 事前講習
rosylilly
3
3.6k
GitHub Actions を導入した経緯
tamago3keran
1
420
ANR overview at Uber + Leveraging ApplicationExitInfo API
yhartanto
0
320
Independently together: better developer experience & App performance
bcinarli
0
150
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
19
1.2k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
349
27k
We Have a Design System, Now What?
morganepeng
35
2.9k
Typedesign – Prime Four
hannesfritz
33
1.3k
A Tale of Four Properties
chriscoyier
149
21k
Teambox: Starting and Learning
jrom
123
7.7k
How GitHub Uses GitHub to Build GitHub
holman
465
280k
Robots, Beer and Maslow
schacon
152
7.1k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
224
49k
VelocityConf: Rendering Performance Case Studies
addyosmani
316
22k
Fantastic passwords and where to find them - at NoRuKo
philnash
27
1.5k
Designing for humans not robots
tammielis
241
23k
Transcript
mockito-kotlin Keisuke Kobayashi Android Test Night #2
About Me • Keisuke Kobayashi • GitHub, QIita: kobakei •
Twitter: kobakei122 • Kyash, Inc • ݸਓࣄۀओ
mockito-kotlin͍͍ͧ
mockito-kotlin • KotlinͰMockitoΛ͏ͨΊͷϥΠϒϥϦ • https://github.com/nhaarman/mockito-kotlin • ˒800 over
Ͳ͕͍͍͔͜ • ϞοΫ͕ݟ͘͢ͳΔ • Null҆શରԠ • άϩʔόϧؔͷՃ • whenରԠ
Mockito in Java // Java import static org.mockito.Mockito.*; Hoge mock
= mock(Hoge.class); when(mock.sayHello()).thenReturn("Hello"); when(mock.sayBye()).thenReturn("Bye");
Convert to Kotlin // Kotlin import org.mockito.Mockito.* val mock =
mock(Hoge::class.java) `when`(mock.sayHello()).thenReturn("Hello") `when`(mock.sayBye()).thenReturn("Bye")
mockito-kotlin // Kotlin import com.nhaarman.mockito_kotlin.* val mock = mock<Hoge> {
on { sayHello() } doReturn "Hello" on { sayBye() } doReturn "Bye" }
ݟ͍͢
Null҆શରԠ • Null҆શͷ͍ͤͰɺMockitoͷanyͰNPE • NonNullͳҾʹanyΛ͢ͱൃੜ • anyͱanyOrNull
άϩʔόϧؔ • any, anyOrNull • atLeast, only, never • verify
• whenever
when • Mockitoͷwhenϝιου • Kotlinͷwhen༧ޠ • `when`ͱॻ͔͘͠ແ͍ • mockito-kotlinͰΘΓʹwheneveron͕ ͑Δ
mockito-kotlin͍͍ͧ
Thanks!