CppUTest-Test-Adapter icon indicating copy to clipboard operation
CppUTest-Test-Adapter copied to clipboard

Getting test runner working with Linux and CMake

Open tank104 opened this issue 5 months ago • 3 comments

Hi, I am trying to get this test runner working on Linux (WSL to be precise) and we use CMake.

To do the build I do:

cd {projectpath}\build\cpputests_tests cmake ../../ make

and that runs the build and tests.

I can't see any .exe file (as on linux), and don't even know where the runner would go.

Test source code is in:

{projectpath}\tests\cpputest

CMakeLists.txt looks like:


# (1) Look for installed version of CppUTest
if(DEFINED ENV{CPPUTEST_HOME})
    message(STATUS "Using CppUTest home: $ENV{CPPUTEST_HOME}")
    set(CPPUTEST_INCLUDE_DIRS $ENV{CPPUTEST_HOME}/include)
    set(CPPUTEST_LIBRARIES $ENV{CPPUTEST_HOME}/lib)
    set(CPPUTEST_LDFLAGS CppUTest CppUTestExt)
else()
    find_package(PkgConfig REQUIRED)
    pkg_search_module(CPPUTEST REQUIRED cpputest>=3.8)
    message(STATUS "Found CppUTest version ${CPPUTEST_VERSION}")
endif()

# (2) Our unit tests sources
set(TEST_APP_NAME ${APP_NAME}_tests)
set(TEST_SOURCES
    ../mocks/ActivityMock.cpp
    ../mocks/ChoreMock.cpp
    ../mocks/FriendMock.cpp
    ../mocks/MessageMock.cpp
    ../mocks/PocketMoneyMock.cpp
    ./common/DeviceSummaryTest.cpp
    main.cpp
)

# (3) Take care of include directories
include_directories(${CPPUTEST_INCLUDE_DIRS} 
    ../../src/common
    ../../include
)
link_directories(${CPPUTEST_LIBRARIES})

# (4) Build the unit tests objects and link then with the app library
add_executable(${TEST_APP_NAME} ${TEST_SOURCES})
target_link_libraries(${TEST_APP_NAME} ${APP_LIB_NAME} ${CPPUTEST_LDFLAGS})

# (5) Run the test once the build is done
add_custom_command(TARGET ${TEST_APP_NAME} COMMAND ./${TEST_APP_NAME} POST_BUILD)

tank104 avatar Sep 02 '24 05:09 tank104