Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
mockito-kotlin
Search
Keisuke Kobayashi
December 15, 2017
Programming
550
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
mockito-kotlin
Android Test Night #2
Keisuke Kobayashi
December 15, 2017
More Decks by Keisuke Kobayashi
See All by Keisuke Kobayashi
AI 1st でエンタープライズ SaaS を立ち上げる / AI 1st Enterprise SaaS
kobakei
1
290
プロダクト開発をAI 1stに変革する〜SaaS is dead時代で生き残るために〜 / AI 1st Product Development
kobakei
0
3k
今日から始める依存性の注入 / First Time Dependency Injection
kobakei
26
7.8k
iOSアプリの技術的負債をどう返済したか / How to repay the technical debt of iOS app
kobakei
2
1k
iOSアプリ内で不正なSSL証明書を検知する / SSL Pinning for iOS apps
kobakei
34
12k
Kyashアプリ開発の現場
kobakei
4
3k
Review of Google I/O 2017 & Prepare for Google I/O 2018
kobakei
0
350
APIクライアントをCodableで置き換えた話
kobakei
0
1.7k
開発者が知っておきたい通知の歴史
kobakei
9
7.9k
Other Decks in Programming
See All in Programming
プロポーザルを書いてもらう
pvcresin
0
560
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
530
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
250
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
210
What's New in Android 2026
veronikapj
0
270
KotlinConf Extended South Korea 2026 Keynote
l2hyunwoo
0
110
VibeCodingからAgenticWorkflowへ
starfish719
0
690
MySQLとPostgreSQLって何が違うの?
akagami
0
120
Webエンジニアなのにブラウザの仕組みがわからないので、Pythonで自作してみた
tatsuki12
1
550
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
330
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
220
FastAPI の並行処理モデルを完全に理解する
hoto17296
1
320
Featured
See All Featured
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
660
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
230
The Language of Interfaces
destraynor
162
27k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
280
WCS-LA-2024
lcolladotor
0
800
The SEO Collaboration Effect
kristinabergwall1
1
520
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
270
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.9k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
300
Paper Plane
katiecoart
PRO
2
53k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
700
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
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!