File structure to satisfy both building and testing?

I can almost garuantee you that tests will fail, you throw all Arduino libraries in lib_deps which cannot be executed out of the box since there is no Arduino framework for native computers installed.

Look at the dependency graph with pio test -e desktop -vvv

Dependency Graph
|-- BarcodeDisplay (License: Unknown, Path: C:\Users\Max\Downloads\BLE-keyboard-and-barcode-display-master\lib\BarcodeDisplay)
|   |-- Code128bEncoder (License: Unknown, Path: C:\Users\Max\Downloads\BLE-keyboard-and-barcode-display-master\lib\Code128bEncoder)
|   |-- BarcodeRenderer (License: Unknown, Path: C:\Users\Max\Downloads\BLE-keyboard-and-barcode-display-master\lib\BarcodeRenderer)
|   |-- Screen (License: Unknown, Path: C:\Users\Max\Downloads\BLE-keyboard-and-barcode-display-master\lib\Screen)
|-- Code128bEncoder (License: Unknown, Path: C:\Users\Max\Downloads\BLE-keyboard-and-barcode-display-master\lib\Code128bEncoder)
|-- BarcodeRenderer (License: Unknown, Path: C:\Users\Max\Downloads\BLE-keyboard-and-barcode-display-master\lib\BarcodeRenderer)
|-- Screen (License: Unknown, Path: C:\Users\Max\Downloads\BLE-keyboard-and-barcode-display-master\lib\Screen)
|-- Unity @ 2.5.2 (License: MIT, Path: C:\Users\Max\Downloads\BLE-keyboard-and-barcode-display-master\.pio\libdeps\desktop\Unity)

However, when properly properly specifying that these tests are to be excluded since your tests don’t require them using

[env:desktop]
platform = native
lib_ignore = 
   BarcodeDisplay
   Screen
lib_ldf_mode = chain+
test_ignore = embedded/*

I get…

> pio test -e desktop
Verbosity level can be increased via `-v, -vv, or -vvv` option
Collected 1 tests

Processing * in desktop environment
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Building...
Testing...
test\test_Code128bEncoder.cpp:152: message_is_encoded   [PASSED]
----------------------------------------------------------------------------------------------- desktop:* [PASSED] Took 1.31 seconds -----------------------------------------------------------------------------------------------
============================================================================================================= SUMMARY ============================================================================================================= 
Environment    Test    Status    Duration
-------------  ------  --------  ------------
desktop        *       PASSED    00:00:01.306
============================================================================================ 1 test cases: 1 succeeded in 00:00:01.306 ============================================================================================ 

For testing libs that are dependent on Arduino, use GitHub - FabioBatSilva/ArduinoFake: Arduino mocking made easy. Also used in the official example (platformio-examples/platformio.ini at develop · platformio/platformio-examples · GitHub).

1 Like