Platformio.ini environment set build_type = test causes "Nothing to build" error

I got a question about the usage of platfomio.ini build_type=test when I am trying to sift through an unit-test configuration originally for PlatformIO 4.

When I set the build_type = test on a configuration, the project configuration will return -

Error: Nothing to build. Please put your test suites to the ‘/home/williamto/project123/test’ folder and the configuration is unusable regardless of test_build_src setting.

I am not sure whether there is need for an unique configuration for unit testing, but at the same time not sure whether the PIO_UNIT_TESTING will be enforced without build_type setting.

File hierarchy for tests has changed significantly in newer PlatformIO core versions, now in test/, there should be folders starting with test_..., check out

Hi Max,

This is the platformio.ini for a unit test configuration -

[env:test]
platform = <platform>
framework = mbed
board = <board>
build_type = test
build_flags =
${env.build_flags}
-DPIO_FRAMEWORK_MBED_RTOS_PRESENT
-Wl,-Map=${BUILD_DIR}/firmware.map
test_build_src = yes

This is my directory structure under project’s test/ subdirectory -

Under test_embedded I have the following -

test.h
test.cpp
test_main_embedded.cpp

Does the filenames under test_* subdirectories matter?

Also from the example you quoted, I don’t see the usage of build_type = test anymore.

Update on 17/7 -

If I move the contents in test_embedded/ into the main test/ subdirectory the “Error: nothing to build” disappears. However if I move to the same directory structure as shown in the example PlatformIO complains about nothing to build.

I finally understand why now - The PlatformIO test framework picks up the test cases under the test/ subdirectory and runs those tests according to the currently selected environment. I do not need a separate [env:test] configuration to run any of the unit tests defined under the test/ subdirectory and it is incorrect to do so.

So I deleted the extra [env:test] configuration and then run the defined unit tests with pio test command.