Hi I working with ESP32C3 C++ and used to work in Eclipse-Espressif IDE + manually launched Google Tests for not embedded specific buisness logic. Testing without uploading speeds up some parts. I want to switch to VSC/Platformio.
I want to have option to add selected files and test them by running on windows.
How can I achieve this? My first idea was to have 2 envs in .ini file:
[env:native]
platform = native
test_framework = googletest
[env:esp32-c3-devkitm-1]
platform = espressif32
board = esp32-c3-devkitm-1
framework = espidf
monitor_speed = 115200
;test_framework = googletest
But after launching test icon from bottom bar it includes main.cpp and fails.
Actually I dont want to include main.cpp in Uni Tests. In the mentioned manual solutions I had cmake in which I was adding files to be testd like so:
cmake_minimum_required(VERSION 3.14)
# set project name - will be used later
project(my_project)
# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()
add_executable(${PROJECT_NAME}
${PROJECT_SOURCE_DIR}/test_main.cpp
${PROJECT_SOURCE_DIR}/test_ringbuffer.cpp
${PROJECT_SOURCE_DIR}/test_service_data.cpp
${PROJECT_SOURCE_DIR}/test_commands_protocol.cpp
${PROJECT_SOURCE_DIR}/test_netw_objects.cpp
${PROJECT_SOURCE_DIR}/test_payload.cpp
${PROJECT_SOURCE_DIR}/../Company/Src/RingBuffer.cpp
${PROJECT_SOURCE_DIR}/../Company/Src/service_data.cpp
${PROJECT_SOURCE_DIR}/../Company/Src/Payload.cpp
${PROJECT_SOURCE_DIR}/../Company/Src/networking_objects.cpp
${PROJECT_SOURCE_DIR}/../Company/Src/gui_event.cpp
${PROJECT_SOURCE_DIR}/../cJSON/Src/cJSON.c
)
target_link_libraries(${PROJECT_NAME}
GTest::gtest_main
)
target_include_directories(${PROJECT_NAME}
PRIVATE ${PROJECT_SOURCE_DIR}/../Company/Inc
PRIVATE ${PROJECT_SOURCE_DIR}/../cJSON/Inc
)
include(GoogleTest)
gtest_discover_tests(${PROJECT_NAME})