Register / Login  |  Desktop view  |  Jump to bottom of page

IoAbstraction & TaskManagerIO » Unit Testing in Platformio using MockIoAbstraction.h

Author: dobrien32
30/01/2021 10:40:00
I have recently been using Platformio to develop an ESP32 program. The program leverages the IoAbstraction library and I am trying to unit test my program, however when running a simple native unit test it fails to compile when I #include <MockIoAbstraction.h> indicating the library cannot be found.

The native calculator example (https://github.com/platformio/platformio-examples/tree/develop/unit-testing/calculator) compiles and runs on my Windows 10 PC (compiler is Mingw).

When I add the IOAbstraction library using the Platformio IDE and add modify my plaformio.ini env as follows:
[env:native]
platform = native
test_ignore = test_embedded
lib_deps = davetcc/IoAbstraction@^1.6.7

the library is shown in the IDE under pio/libdeps/native folder.

I add the line
#include <IoAbstraction.h>
to test_desktop/test_calculator.cpp and attempt to run the test which fails to compile with the following result/error message:

Processing test_desktop in native environment
--------------------------------------------------------------------------------------------------------------------------------------------------------Building...
test\test_desktop\test_calculator.cpp:19:10: fatal error: MockIoAbstraction.h: No such file or directory

***************************************************************************
* Looking for MockIoAbstraction.h dependency? Check our library registry!
*
* CLI > platformio lib search "header:MockIoAbstraction.h"
* Web > https://platformio.org/lib/search?query=header:MockIoAbstraction.h
*
***************************************************************************

#include <MockIoAbstraction.h>
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
*** [.pio\build\native\test\test_desktop\test_calculator.o] Error 1
============================================================== [FAILED] Took 0.83 seconds ==============================================================
Test Environment Status Duration
------------ ------------- -------- ------------
test_common native PASSED 00:00:00.832
test_desktop native FAILED 00:00:00.830
======================================================== 1 failed, 1 succeeded in 00:00:01.663 ========================================================

I'm not sure what to do next, and looking for any suggestions as to how to get platformio to see the library and successfully compile this test. Thanks in advance for any pointers or examples to help get me started unit testing with MockIoAbstraction.h

Author: davetcc
30/01/2021 10:50:03
It can sometimes be a bit tricky, PlatformIO picks up libraries that should be included by looking at your main file and also header files by default IIRC. I recommend if you're running into problems you set the mode to chain+, you can read about that over on the platformIO site: https://docs.platformio.org/en/latest/librarymanager/ldf.html

The easiest option is to add the IoAbstraction.h header file include directly to your main file, that is the file containing either main() or setup() and loop(), I think that will make it pick up the dependency. Worst case if you still don't pick it up, add the dependency directly in the platformio.ini file (see the docs above).


Author: dobrien32
01/02/2021 04:06:21
Hi Dave. Thanks for taking the time to respond and for the excellent library you have built - it has been very helpful on my current ESP32 project.

I will read up on the chain+ mode.

I believe I set the dependency directly in the platformio.ini file already per my original post but it did not work. Is this what you meant?
[env:native]
platform = native
test_ignore = test_embedded
lib_deps = davetcc/IoAbstraction@^1.6.7



Author: davetcc
01/02/2021 08:04:49
Ack, to be honest, I don't use native testing mode, instead I just push tests to an ESP32 with a hardware debugger attached. You may be better bringing this up on the platformIO forum if what I suggested doesn't work.




Register / Login  |  Desktop view  |  Jump to top of page