TDD IN AN IoT WORLD Charles Korn 1 IoT? 2 What is TDD? 3 - - PowerPoint PPT Presentation

tdd in an iot world
SMART_READER_LITE
LIVE PREVIEW

TDD IN AN IoT WORLD Charles Korn 1 IoT? 2 What is TDD? 3 - - PowerPoint PPT Presentation

TDD IN AN IoT WORLD Charles Korn 1 IoT? 2 What is TDD? 3 Test-driven development 4 Test-driven development Test-driven design 5 Its not just about testing your code 6 Its also about designing your code to be testable 7 CODE


slide-1
SLIDE 1

TDD IN AN IoT WORLD

Charles Korn

1

slide-2
SLIDE 2

IoT?

2

slide-3
SLIDE 3

What is TDD?

3

slide-4
SLIDE 4

Test-driven development

4

slide-5
SLIDE 5

Test-driven development Test-driven design

5

slide-6
SLIDE 6

It’s not just about testing your code

6

slide-7
SLIDE 7

It’s also about designing your code to be testable

7

slide-8
SLIDE 8

8

CODE THAT IS DESIGNED TO BE EASY TO TEST

Image credit: weedist.com

slide-9
SLIDE 9

Code that is easy to test is: small simple has a single responsibility

9

slide-10
SLIDE 10

Clean code is: small simple has a single responsibility

10

slide-11
SLIDE 11

But how?

11

slide-12
SLIDE 12

12

Red Green Refactor

slide-13
SLIDE 13

13

Image credits: unicornsrule.com and Nicolò Bertoncin

slide-14
SLIDE 14

Development environment

14

slide-15
SLIDE 15

15

Image credits: Michael Bundscherer, Kevin Kwok, Nicolò Bertoncin, Rflor

≈ ≈ ≉

slide-16
SLIDE 16

Hardware constraints

16

slide-17
SLIDE 17

Long write-run-debug cycle

17

slide-18
SLIDE 18

18

3 6 9 12 Host Target

slide-19
SLIDE 19

Might not have target hardware

19

slide-20
SLIDE 20

Development and production environment differences Hardware constraints Long write-run-debug cycle Target hardware availability

20

slide-21
SLIDE 21

21

Red Green Refactor Test on target hardware

Image credits: Kevin Kwok and Nicolò Bertoncin

slide-22
SLIDE 22

22

Compile Flash Run Compile Flash Run

First 50% of tests Second 50% of tests

slide-23
SLIDE 23

Lots of low-level interactions with hardware

23

slide-24
SLIDE 24

Avoid direct interactions with hardware (or: use good abstractions)

24

slide-25
SLIDE 25

PINA |= (1 << LED_PIN)

  • r

turnOn(LED_PIN) expect(PINA & 0x04 == 1)

  • r

expect(getState(LED_PIN) == ON)

25

slide-26
SLIDE 26

Performance concerns

26

slide-27
SLIDE 27

27

Image credit: scmp.com

slide-28
SLIDE 28

28

IT’S A TRAP!

Image credit: Lucasfilm

slide-29
SLIDE 29

Know what ‘good enough’ looks like Know why it’s required Have a repeatable way to measure it The tests can help you

29

slide-30
SLIDE 30

C and C++

30

slide-31
SLIDE 31

31

Image credit: memecenter.com

slide-32
SLIDE 32

32

Link-time fakes

slide-33
SLIDE 33

33

Function pointers

slide-34
SLIDE 34

34

Virtual classes

slide-35
SLIDE 35

35

Image credit: XKCD

slide-36
SLIDE 36

Go forth and TDD

36

slide-37
SLIDE 37

Before I go…

37

slide-38
SLIDE 38

38

slide-39
SLIDE 39

39

slide-40
SLIDE 40

40

Image credit: blog.tkjelectronics.dk

https://github.com/charleskorn/stm32f4-project-template

slide-41
SLIDE 41

TDD for circuit design

41

slide-42
SLIDE 42

Charles Korn charleskorn.com

THANK YOU