Fortunately not everyone agrees with this sentiment and in the end it was relatively easy to get unit tests working thanks to SeaTest (https://code.google.com/p/seatest/). SeaTest is simple and specifically designed for embedded-c projects.
To get it working for a Microchip MPLabX project I did this
- Created a _test directory in my main projects directory
- Created my unit tests in this directory in test.c
- In this directory created a bash script named "test"
- Copied seatest.c and seatest.h into the directory
- Created dummy PIC include files in this directory
- xc.h
- xc.c
- pic18f4550.h
- Created a plib directory under _test containing
- timers.h
Test runner bash script
#/bin/sh gcc -std=c99 -o test.o -D TESTING -I . -I .. xc.c test.c ../buttons.c ../lcd.c ../dateTime.c ../timerUi.c ../timer.c seatest.c && ./test.o
Nothing fancy... It does this
- Defines a TESTING constant
- Includes the local directory for the "mock" libraries
- Includes the parent directory for my actual code
- Runs ./test.o if the compile succeeds
Mock/Stub files
Most of the stub files (timers.h etc) are empty files just to keep the compiler happy. I then just copied whatever definitions I needed from MPLabX's libraries to get the rest working.
Tests
Tests are then simply a matter of calling a function and using the seatest assert functions.
There definitely are things that are hard to test e.g. interrupt routines but as long as your code is modular you should usually be able to test the methods that e.g. the interrupt routine calls.
Overall I found this to be a very simple approach and it certainly helped me get my project up and running a lot faster with a lot more confidence