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
540
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
2.3k
今日から始める依存性の注入 / 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
2.9k
Review of Google I/O 2017 & Prepare for Google I/O 2018
kobakei
0
340
APIクライアントをCodableで置き換えた話
kobakei
0
1.6k
開発者が知っておきたい通知の歴史
kobakei
9
7.8k
2017年に新規アプリを立ち上げた話
kobakei
2
1.1k
Other Decks in Programming
See All in Programming
コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions
handlename
0
200
米国のサイバーセキュリティタイムラインと見る Goの暗号パッケージの進化
tomtwinkle
2
560
API Platformを活用したPHPによる本格的なWeb API開発 / api-platform-book-intro
ttskch
1
130
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
430
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
430
「抽象に依存せよ」が分からなかった新卒1年目の私が Goのインターフェースと和解するまで
kurogenki
0
110
AIコードレビューの導入・運用と AI駆動開発における「AI4QA」の取り組みについて
hagevvashi
0
430
DSPy入門 Pythonで実現する自動プロンプト最適化 〜人手によるプロンプト調整からの卒業〜
seaturt1e
1
690
モックわからないマン卒業記 ~振る舞いを起点に見直した、フロントエンドテストにおけるモックの使いどころ~
tasukuwatanabe
2
110
Angular-Apps smarter machen mit Gen AI: Lokal und offlinefähig - Hands-on Workshop!
christianliebel
PRO
0
110
The Ralph Wiggum Loop: First Principles of Autonomous Development
sembayui
0
3.7k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
480
Featured
See All Featured
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.4k
Abbi's Birthday
coloredviolet
2
5.3k
How to build a perfect <img>
jonoalderson
1
5.2k
Building an army of robots
kneath
306
46k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
110
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
160
Large-scale JavaScript Application Architecture
addyosmani
515
110k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.5k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
120
What's in a price? How to price your products and services
michaelherold
247
13k
GraphQLの誤解/rethinking-graphql
sonatard
75
11k
エンジニアに許された特別な時間の終わり
watany
106
240k
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!