2
votes

I'd like to unit test single classes I wrote for the arduino platform with VS2015 Express (+VisualMicro).

By single classes I mean the focus is on RingBuffer.h + RingBuffer.cpp. I do not want to emulate an arduino or even run the unit tests on the real hardware.

I have two projects in my solution:

  • Project1 with the code that will run on arduino.
  • Test1 which is a win32 console application that contains the tests and uses simple _ASSERTs to validate the output.

In both projects I use the stdafx.h to define my environment based on preprocessor directives, where I abstract hardware stuff. Example:

#if UNITTEST
typedef unigned short uint16_t
#define DISABLE_INTERRUPTS
#else
#include "Arduino.h"
typedef unsigned int uint16_t
#define DISABLE_INTERRUPTS cli()
#endif

When the project was smaller, I developed the class-implementations within the test project and then I copied the files to the arduino project. But this workflow sucks since the files are not sync.

How can I setup my solution that the unit test project uses the .cpp files from the real arduino code? I managed to include the header files easily by adding a new /INCLUDE directory. But I can't add the sources. I always end up with LNK2019 errors "unresolved external symbol".

1
After reading tons of post... does anyone unittests on adruino? - thomai
For testing Arduino code as a PC program, see e.g. Moon Phase Calendar for Arduino, using Pro Trinket and look in the test folder.. - Martin Moene

1 Answers

0
votes

Ok this one was really easy:

#include "../Project1/RingBuffer.cpp"

Thanks Martin for the demo project!