Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
コードカバレッジを⾒つつユニットテストを書く
Search
Tomoya Miwa
March 18, 2019
Programming
440
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
コードカバレッジを⾒つつユニットテストを書く
Tomoya Miwa
March 18, 2019
More Decks by Tomoya Miwa
See All by Tomoya Miwa
基礎から学ぶ大画面対応(Learning Large-Screen Support from the Ground Up)
tomoya0x00
0
8.5k
Re:VIEWで書いた「Compose で Android の edge-to-edge に対応する」をRoo Codeで発表資料にしてもらった
tomoya0x00
0
730
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
500
できる!ComposeでCollapsingToolbar
tomoya0x00
0
1.1k
Compose の LazyColumn パフォーマンス改善で取り組んだこと
tomoya0x00
0
2.5k
ComposeのMutableStateってどうやってLocal Unit Testすれば良いの??
tomoya0x00
0
1.3k
意外と簡単?Navigation rail導入のお話
tomoya0x00
0
1.7k
Kotlin Coroutines Flow を触ってみた話し
tomoya0x00
2
910
Android for Carsのお話し
tomoya0x00
1
1.1k
Other Decks in Programming
See All in Programming
アクセシビリティから考える情報設計
high_g_engineer
0
430
Java 27新機能 / Java 27 new features
kishida
2
180
App Intentsのビルドプロセスを支える技術
kntkymt
0
480
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
370
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
740
すこし踏み込む CancellationToken
htkym
2
1.5k
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
180
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
1
2k
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
240
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
310
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
570
Featured
See All Featured
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
250
Fireside Chat
paigeccino
43
4k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
610
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
560
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
540
We Have a Design System, Now What?
morganepeng
55
8.3k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
600
WCS-LA-2024
lcolladotor
0
840
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
510
Leo the Paperboy
mayatellez
10
2.3k
Transcript
コードカバレッジを⾒つつ ユニットテストを書く tomoya0x00 Otemachi.apk #02 #otemachi_apk
About me tomoya0x00 Twitter, GitHub, Qiita Android, Embedded system, BLE/BT,
iOS DeNA Co., Ltd. Automotive Business Unit. 前回(Otemachi.apk #01)は⾵邪で登壇できなかった
みなさん、ユニットテストしてますか︖
コードカバレッジは⾒てますか︖
コードカバレッジとは︖
コードカバレッジとは︖ ソースコードのテストされた割合 測定⼿法がいくつかある
測定⼿法、2つだけご紹介
命令網羅(C0) ソースコードの 各⽂ が実⾏されているか fun hoge(x: Int) { println("hoge") if
(x > 0) { println("fuga") } } hoge(x = 1) だけで C0:100%
分岐網羅(C1) ソースコードの 各条件 が実⾏されているか fun hoge(x: Int) { println("hoge") if
(x > 0) { println("fuga") } } hoge(x = 1) と hoge(x = 0) で C1:100%
ユニットテスト + コードカバレッジ
Why?
テストコードが充分か︖ 判断基準の⼀つとして使える
例︓既存コードのリファクタリング
既存コード fun hoge(x: Int): String { if (x >= 3)
return "many" if (x == 2) return "two" if (x == 1) return "one" if (x == 0) return "zero" return "other" }
テストコードを書く @Test fun hogeTest() { assert(hoge(3) == "many") assert(hoge(2) ==
"two") assert(hoge(1) == "one") assert(hoge(0) == "zero") }
このテストコードで充分なのか・・・︖
そこでコードカバレッジ
コードカバレッジを計測する⽅法 Android Studio JaCoCo Other...?
コードカバレッジを計測する⽅法 Android Studio JaCoCo 今回はこちら Other...?
JaCoCoの準備
デフォルト設定だと、 Kotlinが計測対象とならない
JaCoCoの準備 arturdm/jacoco-android-gradle-plugin Issue 37 の JaCoCoの設定 を参考にすればOK ※上記の設定は build variants
も考慮されていてステキ
カバレッジ結果をみてみる
カバレッジ結果をみてみる $ gradlew jacocoDebugReport 実⾏後に、 app/build/reports/jacoco/jacocoDebugReport/html/index.html を開く
None
None
None
None
テストコードを⾜す @Test fun hogeTest() { assert(hoge(3) == "many") assert(hoge(2) ==
"two") assert(hoge(1) == "one") assert(hoge(0) == "zero") assert(hoge(-1) == "other") // ★追加テストコード }
None
無事、カバレッジ100%
リファクタリングも安⼼
Kotlinっぽくしてみる fun hoge(x: Int): String = when { x >=
3 -> "many" x == 2 -> "two" x == 1 -> "one" x == 0 -> "zero" else -> "other" }
None
補⾜ カバレッジ100%だからテストコード完璧、ではない でも、判断基準の⼀つとして使えます カバレッジ100%必達では無い テストコード書きづらいところは、⼿動で確認しても良いんです
ありがとうございました︕