Forked in order to try to get a clean build using or ArduinoFake using cpputest to hopefully resolve the following:
to run:
cmake CMakeLists.txt
make
Note, I added the static libraries generated by cpputest to the folder external/cpputest
because I'm not sure how to do that with cmake
Issues:
- While the original is built using
pio test
, This fails - I didn't translate any of the setup or assertions from unity to cpputest
ArduinoFake
is a simple mocking framework for Arduino.
ArduinoFake
is based on FakeIt and can be used for testing your arduino project natively. No arduino required !
You should include the following header in your test file:
#include <ArduinoFake.h>
Assuming we have the following arduino code:
// src/main.cpp
void loop()
{
// turn the LED on (HIGH is the voltage level)
digitalWrite(LED_BUILTIN, HIGH);
// wait for a second
delay(100);
// turn the LED off by making the voltage LOW
digitalWrite(LED_BUILTIN, LOW);
// wait for a second
delay(100);
}
It can be tested using ArduinoFake
:
#include <ArduinoFake.h>
using namespace fakeit;
// test/test_main.cpp
void test_loop(void)
{
When(Method(ArduinoFake(), digitalWrite)).AlwaysReturn();
When(Method(ArduinoFake(), delay)).AlwaysReturn();
loop();
Verify(Method(ArduinoFake(), digitalWrite).Using(LED_BUILTIN, HIGH)).Once();
Verify(Method(ArduinoFake(), digitalWrite).Using(LED_BUILTIN, LOW)).Once();
Verify(Method(ArduinoFake(), delay).Using(100)).Exactly(2_Times);
}
Checkout the examples for many more examples! Or take a look at the tests
If you get a segfault while running your unit tests, eg:
Program errored with 3221225477 code
Check to make sure you have stubbed all the Arduino methods you are calling.
If you want to extend ArduinoFake
library to add missing functions (for example attachInterrupt
) see contribution guidelines.