Slide 1

Slide 1 text

ANDROID CODE COVERAGE Michal Jeníček, Android Engineer at STRV

Slide 2

Slide 2 text

!2 “Code coverage is not your enemy. It’s a tool to help you with development.“

Slide 3

Slide 3 text

JACOCO JAVA CODE COVERAGE !3 ● Based on byte code, thus is for Kotlin too

Slide 4

Slide 4 text

MISSED INSTRUCTIONS & BRANCHES !4 ● JaCoCo offers two main metrics

Slide 5

Slide 5 text

CODE COVERAGE SAMPLE !5

Slide 6

Slide 6 text

!6

Slide 7

Slide 7 text

!7

Slide 8

Slide 8 text

!8

Slide 9

Slide 9 text

!9

Slide 10

Slide 10 text

!10

Slide 11

Slide 11 text

!11

Slide 12

Slide 12 text

CODE COVERAGE - DOES IT WORTH? !12 Code coverage analysis will ● Help to find missing branches in unit testing ● Help to keep in mind when there will be decreasing coverage with new code Code coverage analysis will NOT ● Ensure, you have been writing tests right

Slide 13

Slide 13 text

CODE COVERAGE - WHEN TO USE !13 Whenever tests are written ● It’s small effort to get helpful tool useful for checking our tests Whenever tests are executed on CI ● It’s small effort to connect code coverage to continuous integration

Slide 14

Slide 14 text

RUN CODE COVERAGE !14

Slide 15

Slide 15 text

Intellij IDEA !15 ● Analyse simple project locally (no standard outputs)

Slide 16

Slide 16 text

GRADLE PLUGIN DEFAULT TASK !16 ● Analyse simple project for CI (instrumentation only)

Slide 17

Slide 17 text

GRADLE PLUGIN CUSTOM TASK !17 ● Analyse complex project for CI

Slide 18

Slide 18 text

UNIT TEST ANALYSIS !18

Slide 19

Slide 19 text

!19

Slide 20

Slide 20 text

!20

Slide 21

Slide 21 text

!21

Slide 22

Slide 22 text

!22

Slide 23

Slide 23 text

!23

Slide 24

Slide 24 text

!24

Slide 25

Slide 25 text

CI GIT INTEGRATION !25

Slide 26

Slide 26 text

CI BRANCH CHECKS !26 ● Run checks with every push to branch automatically ● Merge pull request / branch based on available checks

Slide 27

Slide 27 text

CIRCLE CI 2.0 !27

Slide 28

Slide 28 text

CIRCLE CI 2.0 !28

Slide 29

Slide 29 text

CIRCLE CI 2.0 !29

Slide 30

Slide 30 text

CIRCLE CI 2.0 !30

Slide 31

Slide 31 text

TRAVIS CI !31

Slide 32

Slide 32 text

TRAVIS CI !32

Slide 33

Slide 33 text

TRAVIS CI !33

Slide 34

Slide 34 text

TRAVIS CI !34

Slide 35

Slide 35 text

JENKINS PIPELINE !35

Slide 36

Slide 36 text

JENKINS PIPELINE !36

Slide 37

Slide 37 text

JENKINS PIPELINE !37

Slide 38

Slide 38 text

!38 JENKINS UI

Slide 39

Slide 39 text

CODE COVERAGE OUTPUTS !39

Slide 40

Slide 40 text

OUTPUTS STRUCTURE !40

Slide 41

Slide 41 text

OUTPUTS STRUCTURE !41

Slide 42

Slide 42 text

OUTPUTS STRUCTURE !42

Slide 43

Slide 43 text

OUTPUTS STRUCTURE !43

Slide 44

Slide 44 text

JACOCO LOCAL !44

Slide 45

Slide 45 text

JACOCO LOCAL !45

Slide 46

Slide 46 text

CODECOV !46

Slide 47

Slide 47 text

SAMPLE PROJECT !47

Slide 48

Slide 48 text

I have prepared stub of sample application to apply all kinds of code coverage ability. Sample application is built following way: ● Single activity multi-module application ● Navigation architecture component ● MVVM approach ● DI with Dagger ● Connected to Travis, Circle CI, Jenkins CI & Codecov !48 HTTPS://GITHUB.COM/KOTOMISAK/IMAGE-ANALYZER-ANDROID

Slide 49

Slide 49 text

THAT'S IT Michal Jeníček [email protected]

Slide 50

Slide 50 text

QUESTIONS