PlatformIO Community

Request for PIO feature test_build_flags

When writing unit tests, it is often handy to be able to have access to private data members of an object.
(I know some die-hard unit testers advocate that you should test only via the public interface, but I think a more pragmatic approach makes more sense)

The way I do this is by conditionally disabling the private: keyword when unit testing

#ifndef unitTesting

and then a build flag in platformio.ini can activate this:
build_flags = -D unitTesting

To avoid forgetting to disable this access in normal (production) builds, it would be better if there would be separate build flags for the test builds.

So here is my request for a
test_build_flags = -D unitTesting

Thank you Pio team!

Feature requests should be formally filed in Issues · platformio/platformio-core · GitHub.


  1. PlatformIO automatically activates the PIO_UNIT_TESTING macro when executing tests without you having to specify anything
  1. You can use advanced scripting to check for if you’re currently building for a unit test and add arbitrary flags then. As the trigger, you can use