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
Fixing Broken Robots - Android Mutation Testing
Search
Panini
July 18, 2019
Programming
220
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Fixing Broken Robots - Android Mutation Testing
Panini
July 18, 2019
More Decks by Panini
See All by Panini
Kotlin 1.5 preview
panini
1
480
Java谷園から逃げ出した話
panini
0
410
Kotlin 1.4-rc
panini
0
250
Kotlin Multiplatform
panini
2
700
build.gradle.kts
panini
2
2.5k
Kotlin Multi-platform(?)
panini
1
780
Convert Java file to Kotlin file ⌥⇧⌘K
panini
0
1.2k
Introducing Android P
panini
2
880
Display Cutout
panini
1
680
Other Decks in Programming
See All in Programming
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
2
1.5k
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
930
えっ!!コードを読まずに開発を!?
hananouchi
0
210
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
230
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
230
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
9.1k
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
3.7k
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
260
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
320
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
130
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
270
Utilizing Notion as your number one productivity tool
mfonobong
4
420
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.4k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
390
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Chasing Engaging Ingredients in Design
codingconduct
0
240
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
How to build a perfect <img>
jonoalderson
1
5.8k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
Transcript
Fixing broken robots - Android Mutation Testing DroidConSG 2019 1/45
About me Matthew Vern Twitter Github Mercari, Inc Software Engineer
(Android) @panini_ja panpanini 2/45
Client Engineer Solving problems for our customers Shipping features Improve
existing functionality My job 3/45
A non-shipped feature doesn't provide benefit Ship features as quick
as possible My job 4/45
A shipped, broken feature doesn't provide benefit Ship quality features
as quick as possible My job 5/45
Maintaining quality 6/45
QA Maintaining quality 6/45
QA Code Review Maintaining quality 6/45
QA Code Review Tests Maintaining quality 6/45
How do we know our tests are providing quality Maintaining
quality 7/45
How do we know our tests are providing quality Use
coverage to make sure that our tests are calling production code Maintaining quality 7/45
How do we know our tests are providing quality Use
coverage to make sure that our tests are calling production code changes introduced will not break existing code Maintaining quality 7/45
How do we know our tests are providing quality Use
coverage to make sure that our tests are calling production code changes introduced will not break existing code new code does what it says on the tin Maintaining quality 7/45
Who watches the watchmen? 8/45
How do we know that our tests are quality? Maintaining
quality 9/45
What are tests 10/45
asserting that our assumptions about a piece of code are
correct binary assertions of code correctness What are tests 11/45
Lets fail some tests 12/45
Unit tests assert code behaviour change code behaviour tests fail
???? profit Lets fail some tests 13/45
Mutation testing 14/45
proposed by Richard Lipton in 1971 computationally expensive, not a
viable testing solution until recently Mutation testing 15/45
1. Create a mutant 2. Run test suite 3. Confirm
if mutant was detected or not 4. Repeat Mutation testing steps 16/45
A mutant is a biological entity which has undergone a
change in its genetic structure. What is a mutant? 17/45
A mutant is a code block which has undergone a
change in its structure. What is a mutant? 18/45
class SessionController( private val sessions: MutableList<Session> ) : EpoxyController() {
fun setSessions(sessions: List<Session>) {} override fun buildModels() {} fun generateModels(sessions: List<Session>): List<SessionModel> {} } Creating mutations 19/45
Creating mutations fun setSessions(sessions: List<Session>) { this.sessions.clear() this.sessions.addAll(sessions) requestModelBuild() }
20/45
Creating mutations override fun buildModels() { generateModels(sessions) .forEach { it.addTo(this)
} } 21/45
Creating mutations fun generateModels(sessions: List<Session>): List<SessionModel> { return sessions .map
{ session SessionModel_() .title(session.title) .imageUrl( if (session.speaker.profileImage "") { session.speaker.profileImage } else { null } ) } } 22/45
Creating mutations 23/45
Competent Programmer Hypothesis Creating mutations 23/45
Competent Programmer Hypothesis Coupling Effect Creating mutations 23/45
Replaces relational operators with boundary counterpart Original Original Mutated Mutated
< <= <= < > >= >= > Conditionals boundary 24/45
Conditionals boundary original if (currentTime < startTime) { do something
} mutated if (currentTime startTime) { do something } 25/45
Negates conditional checks Original Original Mutated Mutated == != !=
== <= > > <= Negate Conditionals 26/45
Negate Conditionals original fun buildModels() { SessionModel_() .title(session.title) .imageUrl( if
(session.speaker.profileImage "") { session.speaker.profileImage } else { null } ) } mutated fun buildModels() { SessionModel_() .title(session.title) .imageUrl( if (session.speaker.profileImage "") { session.speaker.profileImage } else { null } ) } 27/45
removes void method calls Remove void calls 28/45
Remove void calls original fun setSessions(sessions: List<Session>) { this.sessions.clear() this.sessions.addAll(sessions)
requestModelBuild() } mutated fun setSessions(sessions: List<Session>) { this.sessions.clear() this.sessions.addAll(sessions) } 29/45
So what? 30/45
Code coverage, but better Why mutation testing 31/45
1. Introduce a fault into production code 2. Use code
coverage to determine which tests to run 3. Run tests 4. Confirm if fault was detected or not 5. Repeat Mutation testing The better way 32/45
That's a lot of work you expect us to do
there bud 33/45
Pitest 34/45
mutation testing system mutants stored in memory outputs pretty reports
Gradle plugin Pitest pitest.org 35/45
apply plugin: pitest generates pitest<Variant> tasks Gradle plugin szpak/gradle-pitest-plugin 36/45
37/45
written by Karol Wrótniak, forked from szpak/gradle-pitest-plugin works with Android
projects has some Android specific helpers (eg: generating mockable Android jar) Android Gradle plugin koral--/gradle-pitest-plugin 38/45
plugins { id("pl.droidsonroids.pitest") } pitest { excludeMockableAndroidJar = false targetClasses
= setOf("jp.co.panpanini.mypackage.*") outputFormats = setOf("XML", "HTML") } Android Gradle plugin 39/45
id("pl.droidsonroids.pitest") plugins { } pitest { excludeMockableAndroidJar = false targetClasses
= setOf("jp.co.panpanini.mypackage.*") outputFormats = setOf("XML", "HTML") } Android Gradle plugin 39/45
pitest { excludeMockableAndroidJar = false targetClasses = setOf("jp.co.panpanini.mypackage.*") outputFormats =
setOf("XML", "HTML") } plugins { id("pl.droidsonroids.pitest") } Android Gradle plugin 39/45
excludeMockableAndroidJar = false plugins { id("pl.droidsonroids.pitest") } pitest { targetClasses
= setOf("jp.co.panpanini.mypackage.*") outputFormats = setOf("XML", "HTML") } Android Gradle plugin 39/45
targetClasses = setOf("jp.co.panpanini.mypackage.*") plugins { id("pl.droidsonroids.pitest") } pitest { excludeMockableAndroidJar
= false outputFormats = setOf("XML", "HTML") } Android Gradle plugin 39/45
outputFormats = setOf("XML", "HTML") plugins { id("pl.droidsonroids.pitest") } pitest {
excludeMockableAndroidJar = false targetClasses = setOf("jp.co.panpanini.mypackage.*") } Android Gradle plugin 39/45
Demo 40/45
Pitest tips & tricks 41/45
MutationInterceptor Removes mutants for Kotlin generated code Pitest kotlin pitest/pitest-kotlin
42/45
Run PITest on Unit tests only 43/45
Run PITest on CI 44/45
Mutation Testing panpanini/mutation_testing Github: panpanini Twitter: panini_ja 45/45