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
It’s not just about testing your code 6
It’s also about designing your code to be testable 7
CODE THAT IS DESIGNED TO BE EASY TO TEST Image credit: weedist.com 8
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
Red Green Refactor 12
Image credits: unicornsrule.com and Nicolò Bertoncin 13
Development environment 14
≈ ≈ ≉ Image credits: Michael Bundscherer, Kevin Kwok, Nicolò Bertoncin, R fl or 15
Hardware constraints 16
Long write-run-debug cycle 17
12 9 6 3 0 Host Target 18
Might not have target hardware 19
Development and production environment di ff erences Hardware constraints Long write-run-debug cycle Target hardware availability 20
Red Green Test on Refactor target hardware Image credits: Kevin Kwok and Nicolò Bertoncin 21
Compile Flash Run Compile Flash Run First 50% of tests Second 50% of tests 22
Lots of low-level interactions with hardware 23
Avoid direct interactions with hardware (or: use good abstractions) 24
PINA |= (1 << LED_PIN) or turnOn(LED_PIN) expect(PINA & 0x04 == 1) or expect(getState(LED_PIN) == ON) 25
Performance concerns 26
Image credit: scmp.com 27
IT’S A TRAP! Image credit: Lucas fi lm 28
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
Image credit: memecenter.com 31
Link-time fakes 32
Function pointers 33
Virtual classes 34
Image credit: XKCD 35
Go forth and TDD 36
Before I go… 37
38
39
https://github.com/charleskorn/stm32f4-project-template Image credit: blog.tkjelectronics.dk 40
TDD for circuit design 41
THANK YOU Charles Korn charleskorn.com
Recommend
More recommend