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
1
530
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
7.5k
iOSアプリの技術的負債をどう返済したか / How to repay the technical debt of iOS app
kobakei
2
980
iOSアプリ内で不正なSSL証明書を検知する / SSL Pinning for iOS apps
kobakei
34
12k
Kyashアプリ開発の現場
kobakei
4
2.8k
Review of Google I/O 2017 & Prepare for Google I/O 2018
kobakei
0
320
APIクライアントをCodableで置き換えた話
kobakei
0
1.6k
開発者が知っておきたい通知の歴史
kobakei
9
7.6k
2017年に新規アプリを立ち上げた話
kobakei
2
1.1k
Everything of CI/CD in Kyash Android
kobakei
0
1.7k
Other Decks in Programming
See All in Programming
物語を動かす行動"量" #エンジニアニメ
konifar
14
5.6k
Google I/O recap web編 大分Web祭り2025
kponda
0
2.9k
コンテキストエンジニアリング Cursor編
kinopeee
1
730
デザインシステムが必須の時代に
yosuke_furukawa
PRO
2
130
250830 IaCの選定~AWS SAMのLambdaをECSに乗り換えたときの備忘録~
east_takumi
0
330
TROCCO×dbtで実現する人にもAIにもやさしいデータ基盤
nealle
0
370
Claude Codeで挑むOSSコントリビュート
eycjur
0
180
ECS初心者の仲間 – TUIツール「e1s」の紹介
keidarcy
0
110
兎に角、コードレビュー
mitohato14
0
160
開発チーム・開発組織の設計改善スキルの向上
masuda220
PRO
17
9.2k
The State of Fluid (2025)
s2b
0
200
Improving my own Ruby thereafter
sisshiki1969
1
130
Featured
See All Featured
The Cult of Friendly URLs
andyhume
79
6.6k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
8
490
Statistics for Hackers
jakevdp
799
220k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
61k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.9k
Unsuck your backbone
ammeep
671
58k
Done Done
chrislema
185
16k
The Language of Interfaces
destraynor
160
25k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.9k
Into the Great Unknown - MozCon
thekraken
40
2k
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!