iot best practices: unit testing
TRANSCRIPT
![Page 1: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/1.jpg)
IOT BEST PRATICES: TESTING THINGS
(for embedded development that sucks less)
@farmckon @BuLogics
![Page 2: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/2.jpg)
EMBEDDED DEVELOPMENT IS PAINFULIt doesn’t have to be.
![Page 3: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/3.jpg)
EMBEDDED DEVELOPMENT TESTING IS PAINFULIt doesn’t have to be.
![Page 4: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/4.jpg)
About Me
• Far McKon• 10+ years in Embedded System &
Firmware• Lead Engineer @ BuLogics, Inc
![Page 5: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/5.jpg)
About Here
• Arcweb• arcweb.co • Smart Businesses Need Smarter
Software• BuLogics & StratIS
• bulogics.com & stratisems.com• Your Wireless Partners
• HT Gabe Torres • (first draft of talk, not at Automatic)
![Page 6: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/6.jpg)
We are going to talk about
• What are Embedded Systems• Unit Testing• Unity/cmock/Ceedling tools.• Example test setup
![Page 7: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/7.jpg)
What are embedded systems?
• 8-bit microCs to powerful ARM cores• Interface with physical systems• Programmed in C• Memory constrained• Single function (not general purpose)• Designs usually price driven, or power-limits driven
![Page 8: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/8.jpg)
What is Unit Testing
• Test driven development (TDD)• Functional , Integration, Unit tests • Write test Functional tests first, (it will fail) • Write the unit tests (they will fail) • Write the code then write code
• Success?
• Success? • Clean Design• Sometimes hard in embedded projects
![Page 9: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/9.jpg)
Example:uint8_t AddNumbers(uint8_t x, uint8_t y) { return x+y; }
void test_AddNumbersShouldAddCorrectly(void) { uint8_t result = AddNumbers(2, 4); TEST_ASSERT_EQUAL(6, result); }
void test_AddNumbersShouldHandleOverflow(void) { uint8_t result = AddNumbers(0xFF, 1); TEST_ASSERT_EQUAL(0, result); }
![Page 10: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/10.jpg)
Test Output:prompt$ rake test:simple
Test 'test_simple.c'--------------------Running test_simple.out.------------------------- OVERALL UNIT TEST SUMMARY -------------------------TESTED: 2 PASSED: 2 FAILED: 0 IGNORED: 0
![Page 11: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/11.jpg)
Lions, Tigers, and Bears
• Cmock• Mock/stub generator for C (C++).
•Unity • simple Unit Testing for C (C).
• Ceedling• Ruby/Rake-based build and test system for C projects
•Unity uses cmock,
• Ceedling uses unity
• Just use ceedling
![Page 12: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/12.jpg)
Example Creating Setup (ceedling)Git clone SOME_PROJECTcd SOME_PROJECT git submodule update –init cd ..Ceedling new SOME_PROJECT(skip duplicates if any warning of dup files)
cd SOME_PROJECT ceedling test:all
![Page 13: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/13.jpg)
Example Project Setup (ceedling)- build # Temporary build files- project.yml # Ceedling configuration- rakefile.rb # Rakefile to invoke ceedling- src # C source files - simple.c - simple.h- test # Test files, all prefixed by test_ - support # tools, fakes, etc - test_simple.c
![Page 14: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/14.jpg)
Example test_simple.cvoid setUp(void){ //runs before every test}
void tearDown(void){ //runs after every test}
void test_ShouldDoSomething(void){ TEST_MESSAGE("This test should do something");}
![Page 15: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/15.jpg)
$Live code
I don’t usually make a fool of myself during my talks, but when I do, I do it as a live demo….
![Page 16: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/16.jpg)
ON DEVICE DEBUGGING IS YOUR LAST RESORT
![Page 17: IoT Best Practices: Unit Testing](https://reader035.vdocuments.mx/reader035/viewer/2022081401/55c47a6cbb61eb16688b4637/html5/thumbnails/17.jpg)
Questions? Comments?
Now Go Eat Snacks.@farmckon
Bulogics.comFarMcKon.net
arcweb.co