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
230
プロダクト開発をAI 1stに変革する〜SaaS is dead時代で生き残るために〜 / AI 1st Product Development
kobakei
0
2.7k
今日から始める依存性の注入 / First Time Dependency Injection
kobakei
26
7.7k
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.6k
開発者が知っておきたい通知の歴史
kobakei
9
7.9k
Other Decks in Programming
See All in Programming
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.4k
AIで効率化できた業務・日常
ochtum
0
120
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
120
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
260
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
2
1.2k
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
350
The NotImplementedError Problem in Ruby
koic
1
710
Swiftのレキシカルスコープ管理
kntkymt
0
220
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
2
560
JavaDoc 再入門
nagise
0
320
New "Type" system on PicoRuby
pocke
1
830
3Dシーンの圧縮
fadis
1
730
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
247
13k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
580
Believing is Seeing
oripsolob
1
140
Raft: Consensus for Rubyists
vanstee
141
7.5k
Why Our Code Smells
bkeepers
PRO
340
58k
So, you think you're a good person
axbom
PRO
2
2.1k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
310
Are puppies a ranking factor?
jonoalderson
1
3.5k
Making Projects Easy
brettharned
120
6.7k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
330
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
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!