How are you creating Qt Quick Test with cmake?
-
Hello,
I attempted to integrate a Qt QuickTest into my CMake project but was unsuccessful.CMakeLists.txt
find_package(Qt6 REQUIRED COMPONENTS QuickTest) enable_testing() function(add_qt_test TARGET) add_executable(${TARGET} ${ARGN}) add_test(NAME ${TARGET} COMMAND ${TARGET}) target_link_libraries(${TARGET} PRIVATE Qt6::QuickTest) endfunction() add_qt_test(tst_main_component tst_main_component.cpp)
tst_main_component.cpp
#include <QtQuickTest> QUICK_TEST_MAIN(main_component)
tst_main_component.qml
import QtQuick import QtTest TestCase { name: "main" function test_case1() { compare(1 + 1, 2, "sanity check"); verify(true); } }
I think there are missing parts for the CMake in the section "running tests" of the documentation link below.
https://doc.qt.io/qt-6/qtquicktest-index.htmlCan you provide a minimal example of integrating Qt Quick Tests into a Qt6 CMake project?
-
Hi @CKurdu, I'm a bit late, but I stepped on a solution that worked for me. I wanted to share it here for the benefit of future developers who might be facing the same issue.
CMakeList.txt
cmake_minimum_required(VERSION 3.20) project(tests) enable_testing() find_package(Qt6 REQUIRED COMPONENTS QuickTest Qml) add_definitions(-DQUICK_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") add_executable(${PROJECT_NAME} tst_case.cpp) add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::QuickTest Qt6::Qml )
tst_case.cpp
#include <QtQuickTest> QUICK_TEST_MAIN(tests)
tst_main_component.qml
import QtQuick import QtTest TestCase { name: "main" function test_case1() { compare(1 + 1, 2, "sanity check"); verify(true); } }