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. QML testing
Qt 6.11 is out! See what's new in the release blog

QML testing

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 659 Views
  • 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.
  • B Offline
    B Offline
    Bob64
    wrote on last edited by Bob64
    #1

    Hello,

    I am trying to unit test QML for the first time. I want to test a component that exists in my application. am following the advice in the documentation to use createTemporaryQmlObject but I am getting an error when the test runs that my component is not a type.

    I have put my skeleton QML test in the same directory structure as my existing C++ unit tests (in a new subdirectory) so I have something roughly like this:

    app/
          qml/
                ...
                MyComponent.qml
                ...
    ...
    tests/
        ...
        TestQML/
              TestMyComponent/
                    TestMyComponent.pro
                    tst_mycomponent.cpp
                    tst_MyComponent.qml
    

    If I only put simple Javascript in my tst_MyComponent.qml file (i.e. I don't yet try to reference MyComponent), everything builds and runs OK. I assume that the problem is that I am not properly specifying MyComponent.qml as a dependency of the test project.

    I have tried setting IMPORTPATH += $$PWD/../../../app/qml in my TestMyComponent.pro file. I have also tried specifying the file path as the third argument of createTemporaryQmlObject but neither is working. However, I don't know what format that file path should be in. Is it sufficient to specify it as a relative path "../../../app/qml/IterationAxis.qml"?

    If I specify the IMPORTPATH only I get this error:

    `file:///C:/Qt/5.9.6/msvc2017_64/qml/QtTest/undefined:1:21: MyComponent is not a type`
    

    If I specify the path argument only, I get this error:

    `file:///C:/Qt/app/qml/MyComponent .qml:1:21: MyComponent is not a type`
    

    I have also tried including the file under test in the test project explicitly via "Add existing files..." in QT creator. This adds it as a relative path in DISTFILES in the test project's .pro file. This gives me the error:

    `file:///C:/Qt/5.9.6/msvc2017_64/qml/QtTest/undefined:1:21: MyComponent is not a type`
    

    Any suggestions please?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bob64
      wrote on last edited by
      #2

      This StackOverflow reply suggests a layout very similar to what I have so I guess I am not trying to do something unreasonable.

      Essentially, the question comes down to: how do I ensure that my QML files under test can be found when the test runs?

      1 Reply Last reply
      0

      • Login

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