The main challenge was integrating GTest into the IDF build system. The solution I came up with was a small wrapper component that uses FetchContent to pull GTest from GitHub at build time, restricted to the linux target only, so it never touches the ESP32 binary. The two-phase IDF build also needs a guard (NOT CMAKE_BUILD_EARLY_EXPANSION) to prevent FetchContent from running during dependency scanning.
I put together a repo documenting the setup: https://github.com/aluiziotomazelli/gtest-esp-idf
The first example (01_basic_test) is intentionally simple — just a Sum class with basic arithmetic and constrained addition. The goal is to validate the integration, not the logic. Next chapters may cover GMock and more complex scenarios.
Code: Select all
cd 01_basic_test/host_test/test_sum
idf.py --preview set-target linux
idf.py build
./build/test_sum.elfFeedback welcome, especially if anyone has a cleaner way to handle the wrapper.