Qt: How to organize Unit Test with more than one class?

后端 未结 6 1549
温柔的废话
温柔的废话 2020-12-29 03:10

I have a Qt Unit test (sub)project, which generates me one class (with the main generated by QTEST_APPLESS_MAIN).I can start this from within Qt Creator as cons

6条回答
  •  清歌不尽
    2020-12-29 03:37

    Build with CMake and not QMake, and add two test targets.

    add_executable(firstTest tst_testfirst.cpp)
    add_test(NAME firstTest COMMAND firstTest)
    
    add_executable(secondTest tst_testsecond.cpp)
    add_test(NAME secondTest COMMAND secondTest)
    

    Both tst_testfirst.cpp and tst_testsecond.cpp have their own QTEST_MAIN lines.

    Qt Creator will run both test classes. If you're running them from the command line, you run the tests with "ctest".

提交回复
热议问题