खोज…


बेसिक टेस्ट सूट

# the usual boilerplate setup
cmake_minimum_required(2.8)
project(my_test_project
        LANGUAGES CXX)

# tell CMake to use CTest extension
enable_testing()

# create an executable, which instantiates a runner from
# GoogleTest, Boost.Test, QtTest or whatever framework you use
add_executable(my_test
               test_main.cpp)

# depending on the framework, you need to link to it
target_link_libraries(my_test
                      gtest_main)

# now register the executable with CTest
add_test(NAME my_test COMMAND my_test)

मैक्रो enable_testing() बहुत सारे जादू करता है। सबसे पहले और सबसे महत्वपूर्ण, यह एक अंतर्निहित लक्ष्य test (GNU मेक के लिए; RUN_TESTS for VS) बनाता है, जो, जब चलाया जाता है, तो क्रेस्ट निष्पादित करता है।

add_test() को कॉल अंत में CTest के साथ एक मनमानी निष्पादन योग्य पंजीकृत करता है, इस प्रकार जब भी हम test लक्ष्य कहते हैं, तो निष्पादन योग्य चलता है।

अब, हमेशा की तरह परियोजना का निर्माण करें और अंत में परीक्षण लक्ष्य चलाएं

GNU मेक दृश्य स्टूडियो
make test cmake --build . --target RUN_TESTS


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow