FabioBatSilva / ArduinoFake

Arduino mocking made easy
https://platformio.org/lib/show/1689/ArduinoFake
MIT License
102 stars 47 forks source link

Is there a way to automatically implement stub all functions? #12

Closed dolfandringa closed 4 years ago

dolfandringa commented 4 years ago

External libraries that I am using, are calling a lot of built-in arduino functions (yield/cli/sei/pinMode/etc). I don't care about these calls, but they are resulting in fakeit::UnexpectedMethodCallException anyway. Is there a way to automatically just AlwaysReturn them or something? Right now I am just debugging it by constantly running the tests, checkig the backtrace of where the tests fail, and add an AlwaysReturn in my int main for them. This is kind of tedious.

FabioBatSilva commented 4 years ago

Unless you know what the function should return you are going to get all sorts of random behaviours doing that.. In that case i think you should be mocking the lib if they are compatible with FakeIt or create a a wrapper around the library and mock that.

See : https://github.com/FabioBatSilva/ArduinoFake/blob/master/examples/mock-injection/test/test_my_service.cpp

dolfandringa commented 4 years ago

Thanks. Yeah, I just mocked a much higher level in the mean time, preventing any of the underlying code being called. I guess I'm still getting used to doing this stuff with Fakeit/C/C++ (coming from much higher level languages)