Hello,
I am trying to perform unit testing with googletest. However, I encountered build issues and was not able to perform testing.
Not sure what is the exact platformio.ini settings with googletest.
I tried to read the paltfomio community but was not able to find the solution.
Here are the settings of my platformio:
[env:megaatmega1280]
platform = atmelavr
board = megaatmega1280
framework = arduino
lib_deps = greiman/SdFat @ ^2.2.0, 4dsystems/genieArduino @ ^1.5.3, SPI
monitor_speed = 115200
build_src_flags = -w
test_framework = googletest
check_tool = cppcheck
check_skip_packages = yes
check_severity = high, medium, low
check_flags =
cppcheck: --enable=warning
cppcheck: --inline-suppr
lib_compat_mode = off
build_flags = -std=c++11
-D TESTING ;Build flag for testing
-Igoogletest/include -Igoogletest
test_build_src = true ;Build from the sourde code folder
I created a sample google test under test> googletest_sample.cpp
#include <gtest/gtest.h>
// TEST(...)
// TEST_F(...)
//#if defined(ARDUINO)
#include <Arduino.h>
void setup()
{
// should be the same value as for the `test_speed` option in "platformio.ini"
// default value is test_speed=115200
Serial.begin(115200);
::testing::InitGoogleTest();
// if you plan to use GMock, replace the line above with
// ::testing::InitGoogleMock();
}
void loop()
{
// Run tests
if (RUN_ALL_TESTS();
// sleep for 1 sec
delay(1000);
}
#else
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
// if you plan to use GMock, replace the line above with
// ::testing::InitGoogleMock(&argc, argv);
if (RUN_ALL_TESTS();
// Always return zero-code and allow PlatformIO to parse results
return 0;
}
#endif
Also I have encountered below errors:
Building & Uploading…
In file included from test\googletest_sample.cpp:1:0:
.pio\libdeps\megaatmega1280\googletest\googletest\include/gtest/gtest.h:52:10: fatal error: cstddef: No such file or directory
#include <cstddef>
^~~~~~~~~
compilation terminated.
*** [.pio\build\megaatmega1280\test\googletest_sample.cpp.o] Error 1
Uploading stage has failed, see errors above. Use `pio test -vvv` option to enable verbose output.
Please let me know for any ideas.
Thank you very much.