Unity unit test framework fails when shouldn't

The fakeit mocking framework doesn’t seem to work with PlatformIO unity.

In FakeIt, you can mock SomeClass by doing this:
Mock mock;
When(Method(mock, some_function_in_SomeClass)).Return(0) // makes some_function_in_SomeClass return 0 when its called.

inside the test folder, if you call some_function_in_SomeClass, unity will say that the test failed:

// inside test.cpp in the test folder:
void setUp(void) {
Mock mock;
When(Method(mock, some_function_in_SomeClass)).Return(0);

void some_test_function_that_has_nothing_in_it() {
int main(int argc, char **argv) {


output: test failed!

I haven’t used fakeit but it seems it’s like googles gmock.
Could you provide further information about the platform and framework you use?
The full console output and a example project would be helpful, too :-).

Maybe this example will help?

1 Like

So this example does work - but this example mocks Arduino Classes and objects. I have created my own classes and objects, and it fails when I try to mock my classes.

Also I’m using fakeit while that example is using ArduinoFake. ArduinoFake does not let you mock your own classes unfortunately. It only lets you mock arduino classes like Client.

found the error, fakeit was throwing an error without the error showing up in the terminal.

the Mocked classes need to have virtual functions in it (the class needs to be polymorphic). My class was not polymorphic and hence an assertion was thrown.