By default, PlatformIO does not build the main source code from the src_dir folder in pair with a test source code. If you have a shared/common code between your “main” and “test” programs, you have 2 options:
We recommend splitting the source code into multiple components and placing them into the lib_dir (project’s private libraries and components). Library Dependency Finder (LDF) will find and include these libraries automatically in the build process. You can include any library/component header file in your test or main application source code using
NOT RECOMMENDED. Manually instruct PlatformIO to build the main source code from the src_dir folder in pair with a test source code using the test_build_src option in “platformio.ini” (Project Configuration File):
[env:myenv] platform = ... test_build_src = true
This is very useful if you unit test independent libraries where you can’t split source code.
Please note that you will need to use
#endifguard to hide non-test related source code. For example, own
setup() / loop(), or