PlatformIO Community

Unit Testing with Dependencies


#1

I am trying to setup unit testing for a library of mine that is built on top of another library of mine. The library that I depend upon has some dependencies in the Arduino framework but I have them mocked for testing on the desktop. I have a few tests setup in the base library already and they are passing fine.

I am trying to setup testing on the library that now depends on the original library and it seems like the UNIT_TEST define is not propagating the base library which is causing compilation errors.

PlatformIO Plus (https://pioplus.com) v0.14.1
Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items

============================ [test::heart-rate-display] Building... (1/2) ============================
Please wait...
In file included from src/BaseClasses/ANTPLUS_BaseDataPage.cpp:1:
In file included from src/BaseClasses/ANTPLUS_BaseDataPage.h:6:
In file included from .piolibdeps/ANT_ID353/src/ANT.h:27:
In file included from .piolibdeps/ANT_ID353/src/MainClasses/ANT_Ant.h:4:
.piolibdeps/ANT_ID353/src/BaseClasses/ANT_BaseAnt.h:9:10: fatal error: 'Arduino.h' file not found
#include "Arduino.h"
^~~~~~~~~~~
1 error generated.
In file included from src/BaseClasses/ANTPLUS_BaseMasterProfile.cpp:1:
In file included from src/BaseClasses/ANTPLUS_BaseMasterProfile.h:4:
In file included from src/BaseClasses/ANTPLUS_BaseProfile.h:4:
In file included from src/MainClasses/ANTPLUS_AntPlusRouter.h:7:
In file included from .piolibdeps/ANT_ID353/src/ANT.h:27:
In file included from .piolibdeps/ANT_ID353/src/MainClasses/ANT_Ant.h:4:
.piolibdeps/ANT_ID353/src/BaseClasses/ANT_BaseAnt.h:9:10: fatal error: 'Arduino.h' file not found
#include "Arduino.h"
^~~~~~~~~~~
*** [.pioenvs/native/src/BaseClasses/ANTPLUS_BaseDataPage.o] Error 1
1 error generated.
*** [.pioenvs/native/src/BaseClasses/ANTPLUS_BaseMasterProfile.o] Error 1
In file included from src/BaseClasses/ANTPLUS_BaseProfile.cpp:1:
In file included from src/BaseClasses/ANTPLUS_BaseProfile.h:4:
In file included from src/MainClasses/ANTPLUS_AntPlusRouter.h:7:
In file included from .piolibdeps/ANT_ID353/src/ANT.h:27:
In file included from .piolibdeps/ANT_ID353/src/MainClasses/ANT_Ant.h:4:
.piolibdeps/ANT_ID353/src/BaseClasses/ANT_BaseAnt.h:9:10: fatal error: 'Arduino.h' file not found
#include "Arduino.h"
^~~~~~~~~~~
1 error generated.
*** [.pioenvs/native/src/BaseClasses/ANTPLUS_BaseProfile.o] Error 1
In file included from src/BaseClasses/ANTPLUS_CoreDataPage.cpp:4:
In file included from .piolibdeps/ANT_ID353/src/ANT.h:27:
In file included from .piolibdeps/ANT_ID353/src/MainClasses/ANT_Ant.h:4:
.piolibdeps/ANT_ID353/src/BaseClasses/ANT_BaseAnt.h:9:10: fatal error: 'Arduino.h' file not found
#include "Arduino.h"
^~~~~~~~~~~
In file included from src/BaseClasses/ANTPLUS_BaseSlaveProfile.cpp:1:
In file included from src/BaseClasses/ANTPLUS_BaseSlaveProfile.h:4:
In file included from src/BaseClasses/ANTPLUS_BaseProfile.h:4:
In file included from src/MainClasses/ANTPLUS_AntPlusRouter.h:7:
In file included from .piolibdeps/ANT_ID353/src/ANT.h:27:
In file included from .piolibdeps/ANT_ID353/src/MainClasses/ANT_Ant.h:4:
.piolibdeps/ANT_ID353/src/BaseClasses/ANT_BaseAnt.h:9:10: fatal error: 'Arduino.h' file not found
#include "Arduino.h"
^~~~~~~~~~~
1 error generated.
*** [.pioenvs/native/src/BaseClasses/ANTPLUS_BaseSlaveProfile.o] Error 1
1 error generated.
*** [.pioenvs/native/src/BaseClasses/ANTPLUS_CoreDataPage.o] Error 1
===================================== [ERROR] Took 1.18 seconds =====================================

============================================= [SUMMARY] =============================================
Environment teensy31    [SKIP]
Environment native      [ERROR]
===================================== [ERROR] Took 1.18 seconds =====================================

I was curious if there is any way to force the UNIT_TEST define to exist in the base library so I can compile it for the tests.


#2

nevermind, I figured out the error, I forgot I had not released the code that handles the mocking in the second library so it was grabbing a bad version