TDD IN AN IoT WORLD
Charles Korn
1
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
Charles Korn
1
IoT?
2
What is TDD?
3
Test-driven development
4
Test-driven development Test-driven design
5
It’s not just about testing your code
6
It’s also about designing your code to be testable
7
8
CODE THAT IS DESIGNED TO BE EASY TO TEST
Image credit: weedist.com
Code that is easy to test is: small simple has a single responsibility
9
Clean code is: small simple has a single responsibility
10
But how?
11
12
Red Green Refactor
13
Image credits: unicornsrule.com and Nicolò Bertoncin
Development environment
14
15
Image credits: Michael Bundscherer, Kevin Kwok, Nicolò Bertoncin, Rflor
Hardware constraints
16
Long write-run-debug cycle
17
18
3 6 9 12 Host Target
Might not have target hardware
19
Development and production environment differences Hardware constraints Long write-run-debug cycle Target hardware availability
20
21
Red Green Refactor Test on target hardware
Image credits: Kevin Kwok and Nicolò Bertoncin
22
Compile Flash Run Compile Flash Run
First 50% of tests Second 50% of tests
Lots of low-level interactions with hardware
23
Avoid direct interactions with hardware (or: use good abstractions)
24
PINA |= (1 << LED_PIN)
turnOn(LED_PIN) expect(PINA & 0x04 == 1)
expect(getState(LED_PIN) == ON)
25
Performance concerns
26
27
Image credit: scmp.com
28
Image credit: Lucasfilm
Know what ‘good enough’ looks like Know why it’s required Have a repeatable way to measure it The tests can help you
29
C and C++
30
31
Image credit: memecenter.com
32
Link-time fakes
33
Function pointers
34
Virtual classes
35
Image credit: XKCD
Go forth and TDD
36
Before I go…
37
38
39
40
Image credit: blog.tkjelectronics.dk
https://github.com/charleskorn/stm32f4-project-template
TDD for circuit design
41
Charles Korn charleskorn.com