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.cppvoidloop()
{
// turn the LED on (HIGH is the voltage level)digitalWrite(LED_BUILTIN, HIGH);
// wait for a seconddelay(100);
// turn the LED off by making the voltage LOWdigitalWrite(LED_BUILTIN, LOW);
// wait for a seconddelay(100);
}It can be tested using ArduinoFake:
#include<ArduinoFake.h>usingnamespacefakeit;// test/test_main.cppvoidtest_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.