See https://community.platformio.org/t/getting-started-with-unit-testing/18946 for reference.
The unit tests in test/test_desktop feature examples for unit tests that mock the IoAbstraction library, the Wire library and the Arduino core in general.
A small business logic class is tested that reacts on a switch, using the IoAbstraction library. It is shown how that class can be unit-tested using mocking techniques.
- Install PlatformIO Core
- Download examples source code
- Extract ZIP archive
- Run these commands:
# Change directory to example
> cd platformio-examples/unit-testing/calculator
# Test project
> platformio test
# Test specific environment
> platformio test -e uno
# Process test on native desktop machine
> platformio test -e native