Slide 1

Slide 1 text

@xgouchet Compiler based Testing CodeMobile UK 2019 - Chester

Slide 2

Slide 2 text

@xgouchet About me… Xavier F. Gouchet Android developer since the Cupcake years Lead Android Engineer at WorkWell @xgouchet on every social network you can think of… 2

Slide 3

Slide 3 text

@xgouchet Testing is Hard Let’s let the compiler do most of the hard work for us 3

Slide 4

Slide 4 text

@xgouchet Kotlin / Swift ▧ Statically Typed ▧ Strong Typed ▧ Type Safe ▧ Type Inference 4

Slide 5

Slide 5 text

@xgouchet Basic use case — JSON { "id" : 481516, "title" : "Lorem ipsum dolor sit amet…", "picture" : "https://cloudhost.com/5162342", "created": 1553631328 } 5

Slide 6

Slide 6 text

@xgouchet Basic use case — App Model data class Event( val id: Int, val title: String, val picture: String, val created: Int } 6

Slide 7

Slide 7 text

@xgouchet Primitive Aversion Primitives are lightweight… but lack context 7

Slide 8

Slide 8 text

@xgouchet Use existing types ▧ Integrated in framework and libraries ▧ Zero additional work data class Event( … val created: Date } 8

Slide 9

Slide 9 text

@xgouchet Type Alias ▧ Give context ▧ Prevent invalid assignements ▧ Ease Maintenance typealias Id = Int data class Event( val id: Id, … } 9

Slide 10

Slide 10 text

@xgouchet Type Checking ▧ Limit Primitive Scope ▧ Validate data data class Url(val value: String) { init { val parsedUrl = URL(value) } } data class Event( … val picture: Url } 10

Slide 11

Slide 11 text

@xgouchet Additional gains 11

Slide 12

Slide 12 text

@xgouchet Bonus ▧ Share common operations ▧ Force explicit types ▧ Simplify complex structure 12

Slide 13

Slide 13 text

@xgouchet @xgouchet Thanks! Any questions? 13 Presentation template by SlidesCarnival