Cannot get googletest to compile on my project

Hey everyone,

I am very new to the whole embedded/Arduino/PlatformIO thingy and I did not really do C in the last… 35 years (though I did plenty of other languages ;).

So I started this new project and wanted to be a good citizen and start with tests.
Reading a bit of documentation, I chose googletest as test platform as it is the only one that supports mocking…

Unfortunately, it did not go very far.
As soon as I added the googletest dependency, my project would not compile.
I read something about C++ standard, tried to add that, no dice…

I have added the tests in this branch.
My platformio.ini is here.

Any help for an absolute beginner would be much appreciated.
Many thanks in advance.

Commit Adding Google Test dependency · jmcazaux/esp32_dab_radio@c07611e · GitHub makes no sense, you shouldn’t indent whole blocks of platformio.ini instructions like that, the value = .. lines should always be flush to the left side of the file. You also don’t need to add googletest to the lib_deps because it’s added automatically during the unit test build.

You should look at the exact official reference, that includes an ESP32 + GoogleTest project.

Hey Max,

many thanks for taking the time :folded_hands: .

I have fixed my platformio.ini according to your recommendation.

After some more tinkering (and directing the large command output to a file!), I understood that the error was due to the C++ standard (that was not 17 or above).

I added the following to my platformio.ini and :collision: ! It compiled!

[env:debug]
test_framework = googletest
build_flags = ${env.build_flags}
-std=gnu++17
build_unflags =
-std=gnu++11

I have not written proper tests yet, but the tests copied from the examples definitely do what they are meant to do.

What is strange though that in the IDE, it still looks like it cannot find gtest.h

This line was added to the include path (the one in the Microsoft C++ extension in VSCode)…
${workspaceFolder}/.pio/libdeps/debug/googletest/googletest/include .

Maybe the fact that I am on a Mac is a bit different?
I have not found any specifics for Mac in the installation instructions.

Many thanks for your help anyway!

True, Intellisense does not pick up the headers for gtest in the regular environment unless you write lib_deps = googletest, too. Then it gets resolved properly.