[Logo] TCC discussion forum
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 


This forum is read only and new users cannot register, please ask all new questions either using GitHub discussions, or in Arduino forum tagging @davetcc.

Unit Testing in Platformio using MockIoAbstraction.h RSS feed
Forum Index » IoAbstraction & TaskManagerIO
Author Message
dobrien32


Joined: Jan 30, 2021
Messages: 3
Offline
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
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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).

dobrien32


Joined: Jan 30, 2021
Messages: 3
Offline
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


davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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.
 
Forum Index » IoAbstraction & TaskManagerIO
Go to:   
Mobile view
Powered by JForum 2.7.0 © 2020 JForum Team • Maintained by Andowson Chang and Ulf Dittmer

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.