Unit testing embedded C projects with seatest

Posted on July 25, 2014

I recently wrote my first embedded C project and was surprised to find that unit tests were not as widely used as I would have expected. There seems to be a general opinion that unit tests are less useful for embedded development that for application development. I find this strange because debugging embedded systems is hard compared to application development.

Fortunately not everyone agrees with this sentiment and in the end it was pretty 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

  1. Created a _test directory in my main projects directory
  2. Created my unit tests in this directory in test.c
  3. In this directory created a bash script named “test”
  4. Copied seatest.c and seatest.h into the directory
  5. Created dummy PIC include files in this directory
    1. xc.h
    2. xc.c
    3. pic18f4550.h
  6. Created a plib directory under _test containing
    1. timers.h The idea being that the my test directory (_test) contained files for mocking the Microchip libraries to make testing possible. This turned out to be much simpler than I had feared.

Test runner bash script

    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

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 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