Mocking framework

I just started to use PlatformIO test framework and it’s been great.

However frequently it would be usefull to have a access to a mocking framework.

Have someone used any mocking framework with platformio? I’m open to sugestions.

  • Tried CMock but it seemed inapropriate to C++, and tended to get confused when classes and virtual methods were introduced.

  • Considering GoogleMock right now, but seems like overkill

1 Like

There is no straight forward to mock out objects.

When you say Cmock, I am assuming the ceedling/unity/cmock framework.

It works fine. I am not too sure about the classes and virtual methods.
Afterall, most of the embedded development happens to be mostly C. Maybe thats whay it is not working out.

I manually test using the ceedling framework even in platformio. open a terminal and mock test it out.

Using ceedling directly can be complex when trying to manage both hardware and native builds. I Like the way they implement the mocking framework, it’s just it is not practical to setup everything another time, once platformio is allready up and running.

The discussions here indicated that FakeIt framework has been used with sucess. But I’m new to mocking / test stuff, so I’m kinda lost.

Current project fails to build TimeLib with MinGw, so my goal is to create a mock for that. But I have no clue where to start.

Likewise, I really like the ceedling framework for work. Unfortunately, I am having to do double the work since platformio does not support cmock. I have seen fakeit, but I am used to the ceedling framework and would prefer not to deviate from it.

I do not know about the intricacies of MingW. I have had success with native gcc compiler on ubuntu and MacOS. I ll try the classes and virtual methods on my end and setup and report back my findings.

Thank you @Krishna_Chaitanya . I will also be directing my efforts to make CMock work too.

Hi Bruno,

I got on quite well with FakeIt (GitHub - eranpeer/FakeIt: C++ mocking made easy. A simple yet very expressive, headers only library for c++ mocking.) when I was making my hardware mocking framework. I used it in the tests for one of my libraries here: Transition/test_1.cpp at master · r89m/Transition · GitHub


Thank you for the tip @r89m!

I ended up using FakeIt, C++ support is better resolved in it anyway.

This topic is a little old but just in case this helps anyone, I’ve managed to use ArduinoFake with a lot of success. Only caveat is to set the build_flags outlined here.

1 Like