Simplest example of using Google C++ Testing Framework with CMake

后端 未结 1 1058
耶瑟儿~
耶瑟儿~ 2021-01-30 11:35

I have a very simple C++ library (one header file, one .cpp file). I want to write unit tests for this project using the Google C++ Testing Framework.

Here is the direct

相关标签:
1条回答
  • 2021-01-30 12:15

    Enable CMake's built-in testing subsystem:

    # For make-based builds, defines make target named test.
    # For Visual Studio builds, defines Visual Studio project named RUN_TESTS.
    enable_testing()
    

    Compile an executable that will run your unit tests and link it with gtest and gtest_main:

    add_executable(runUnitTests
        project1_unittests.cpp
    )
    target_link_libraries(runUnitTests gtest gtest_main)
    

    Add a test which runs this executable:

    add_test(
        NAME runUnitTests
        COMMAND runUnitTests
    )
    
    0 讨论(0)
提交回复
热议问题