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
プロダクト開発をAI 1stに変革する〜SaaS is dead時代で生き残るために〜 / AI 1st Product Development
kobakei
0
1.1k
今日から始める依存性の注入 / 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.9k
Review of Google I/O 2017 & Prepare for Google I/O 2018
kobakei
0
320
APIクライアントをCodableで置き換えた話
kobakei
0
1.6k
開発者が知っておきたい通知の歴史
kobakei
9
7.7k
2017年に新規アプリを立ち上げた話
kobakei
2
1.1k
Other Decks in Programming
See All in Programming
コードとあなたと私の距離 / The Distance Between Code, You, and I
hiro_y
0
180
詳しくない分野でのVibe Codingで困ったことと学び/vibe-coding-in-unfamiliar-area
shibayu36
3
5.1k
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
290
Devoxx BE - Local Development in the AI Era
kdubois
0
130
『毎日の移動』を支えるGoバックエンド内製開発
yutautsugi
2
250
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
470
CSC305 Lecture 04
javiergs
PRO
0
270
overlayPreferenceValue で実現する ピュア SwiftUI な AdMob ネイティブ広告
uhucream
0
190
Leading Effective Engineering Teams in the AI Era
addyosmani
7
490
(Extension DC 2025) Actor境界を越える技術
teamhimeh
1
260
CSC305 Lecture 05
javiergs
PRO
0
220
Cursorハンズオン実践!
eltociear
2
1.1k
Featured
See All Featured
Navigating Team Friction
lara
190
15k
Docker and Python
trallard
46
3.6k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.6k
Making Projects Easy
brettharned
120
6.4k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
Why Our Code Smells
bkeepers
PRO
340
57k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
GraphQLとの向き合い方2022年版
quramy
49
14k
The Language of Interfaces
destraynor
162
25k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.1k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
61k
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!