PlatformIO Community

Native Unit Testing trying to import internal modules - ESP8266Wifi

Hey there. I’m trying to create a unit testing workflow for my code.

The problem is: When I try testing my code on native environment importing my modules. Some of those modules require native libraries such as ESP8266Wifi so the test fails (not found headers)

It does the same for MQTT.h and other libraries that run only on the embedded device.

There is any way to mock those headers or make them run properly on my local machine?

At least for the esp8266-libs I have had good experiences with this library


I was about to suggest that, but it mainly mocks the standard Arduino headers, not the ESP8266 libraries. I haven’t yet seen anything that does that. Usually the components are rewritten so that if they’re compiled for native, these headers are not used but input / output is coming from some mock object elsewhere.

I think Arduino Fake doesn’t work for this purpose.

Imagine an example, I must test a Network.cpp class. The class needs some datatypes from MQTT.h library which compiles only for the esp environment.

If I try to include the header Network.h it doesn’t compile because the MQTT.h is missing.

There’s any way to do it?