Hi. I've got good enough with C++ now to get some climate control stuff working with my arduino (with data logging, a custom web server, relay and servo control) but I just don't get how to unit test properly.
I'd like to use Google's gtest framework to make sure that my libraries which deal with the logic of when to activate heaters/dehumidifiers etc. are really doing what they ought to.
After downloading gtest it seems the want it to be used with XCode (which obviously isn't a good fit here), but I can compile the framework to produce two .a (gtest.a and gtest_main.a) libraries.
Is there someway I can get these libraries to be included in the compilation of my project (along with the gtest header files I imagine), so that I can use the gtest features to unit test my code?
Google's framework for writing C++ tests on a variety of platforms (Linux, Mac OS X, Windows, Cygwin, Windows CE, and Symbian). Based on the xUnit architecture. Supports automatic test discovery, a rich set of assertions, user-defined assertions, death tests, fatal and non-fatal failures, value- and type-parameterized tests, various options for running the tests, and XML test report generation.
It's not intended to be run on a Microcontroller platform that doesn't offer features like standard input and standard output.
You can do extremely simple unit testing on the Arduino but then you have to write your own framework and take care that it uses the serial interface to communicate results.
I would use ArduinoUnit if I wanted to run tests on the MicroController, but that's not the aim.
Generally, all logic in the code I've written is abstracted away from classes which contain code for driving the hardware (e.g. setting pins, or reading sensors).
I would like to test the logic in my classes (connecting them to mock objects where necessary), not whether or not they cause the hardware to crash or operate as expected (a different set of concerns).
I really should have done this using a Test Driven Development approach (but the learning curve was steep enough) - in which case ArduinoUnit would definitely have been the wrong approach for rapid development.
Generally, all logic in the code I've written is abstracted away from classes which contain code for driving the hardware (e.g. setting pins, or reading sensors).
If this is the case (good style BTW) you can use any unit test software that runs on your development platform (looks like Mac from your comments). Just take care that you really abstracted consistently and completely because platform-dependent variable types (like "int" or "long int") may ruine your code safety in no time if you run the tests on another platform than the productive code.
Oh, ok. int and long int are platform dependent types? Ouch. I can remember from my uni days that C was tricky to port, but I'd forgotten the rot goes so deep
Oh, ok. int and long int are platform dependent types?
"int" is 16 bits on the Arduino, but 32 bit on Linux to give you an example. I usually take the defined versions ("int16_t", "uint32_t", etc.) which are always the size that the name says.