Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How are you creating Qt Quick Test with cmake?
Qt 6.11 is out! See what's new in the release blog

How are you creating Qt Quick Test with cmake?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.2k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CKurduC Offline
    CKurduC Offline
    CKurdu
    wrote on last edited by CKurdu
    #1

    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.html

    Can you provide a minimal example of integrating Qt Quick Tests into a Qt6 CMake project?

    You reap what you sow it

    1 Reply Last reply
    1
    • D Offline
      D Offline
      dimitar26
      wrote on last edited by
      #2

      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);
          }
      }
      
      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved