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
コードカバレッジを⾒つつユニットテストを書く
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Tomoya Miwa
March 18, 2019
Programming
420
0
Share
コードカバレッジを⾒つつユニットテストを書く
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.1k
Re:VIEWで書いた「Compose で Android の edge-to-edge に対応する」をRoo Codeで発表資料にしてもらった
tomoya0x00
0
660
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
460
できる!ComposeでCollapsingToolbar
tomoya0x00
0
1.1k
Compose の LazyColumn パフォーマンス改善で取り組んだこと
tomoya0x00
0
2.4k
ComposeのMutableStateってどうやってLocal Unit Testすれば良いの??
tomoya0x00
0
1.2k
意外と簡単?Navigation rail導入のお話
tomoya0x00
0
1.6k
Kotlin Coroutines Flow を触ってみた話し
tomoya0x00
2
890
Android for Carsのお話し
tomoya0x00
1
1.1k
Other Decks in Programming
See All in Programming
AIと共に生きる技術選定 2026
sgash708
0
110
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.6k
PCOVから学ぶコードカバレッジ #phpcon_odawara
o0h
PRO
0
280
The Monolith Strikes Back: Why AI Agents ❤️ Rails Monoliths
serradura
0
350
ハーネスエンジニアリングにどう向き合うか 〜ルールファイルを超えて開発プロセスを設計する〜 / How to approach harness engineering
rkaga
24
14k
Angular Signal Forms
debug_mode
0
120
Oxlintとeslint-plugin-react-hooks 明日から始められそう?
t6adev
0
280
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
280
Server-Side Kotlin LT大会 vol.18 [Kotlin-lspの最新情報と Neovimのlsp設定例]
yasunori0418
1
190
GoogleCloudとterraform完全に理解した
terisuke
1
160
検索設計から 推論設計への重心移動と Recall-First Retrieval
po3rin
4
1.1k
ふりがな Deep Dive try! Swift Tokyo 2026
watura
0
240
Featured
See All Featured
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
What's in a price? How to price your products and services
michaelherold
247
13k
KATA
mclloyd
PRO
35
15k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
680
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.5k
Believing is Seeing
oripsolob
1
120
Navigating Team Friction
lara
192
16k
First, design no harm
axbom
PRO
2
1.2k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Chasing Engaging Ingredients in Design
codingconduct
0
170
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
190
Joys of Absence: A Defence of Solitary Play
codingconduct
1
350
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%必達では無い テストコード書きづらいところは、⼿動で確認しても良いんです
ありがとうございました︕