Adding unit tests to inherited project

All,

I have inherited a Platformio based project, targeting the Teensy platform. It builds and runs fine. I would like to start adding unit tests for at least the business logic of any new features I have to add. I am mostly interested in running tests on the host PC, not the target.

I read through the tutorial at Unit Testing of a “Blink” Project — PlatformIO latest documentation and started applying those principles to my project. However, it looks like to compile the project in unit test mode, for the host system, every “non test” file needs to be guarded with “#ifndef UNIT_TEST”? Is this correct? This would be OK if it were just for my project source files, but my project imports a lot of hardware libraries, and it looks like it will not build in host unit test mode unless every source file under the lib directory is also modified with #ifndef UNIT_TEST. Is this actually how the host unit testing is supposed to be configured? Or is there an easier way e.g. where I can just exclude everything under lib from the unit test build?

Thanks,
Fred

Could you try one of these options?

  1. Change Library Dependency Finder Mode to lib_ldf_mode = chain+
  2. Create new environemnt [env:test_conf] in platformio.ini and ignore specific libraries using lib_ignore option.

Thanks!