Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

RTduino/RTduinoMockAPI

Open more actions menu
 
 

Repository files navigation

ArduinoFake

Build Status

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 !

Quickstart

Includes

You should include the following header in your test file:

#include <ArduinoFake.h>

Stubbing

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

Troubleshooting

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.

Contributing

If you want to extend ArduinoFake library to add missing functions (for example attachInterrupt) see contribution guidelines.

Releases

No releases published

Languages

  • C++ 89.3%
  • C 10.1%
  • Other 0.6%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.