Qt Quick QML Unit Test linkage problem
-
I am trying to create unit tests for a practice Qt Quick QML project on Qt 5.12 using Qmake configuration on ubuntu and I am running into problem on how to make my test files able to find and import my custom components in order to test for them.
In my Tests subdir, the .pro file looks like this:
CONFIG += warn_on qmltestcase testlib INCLUDEPATH = $$PWD/../app IMPORTPATH += $$PWD/../app QML_IMPORT_PATH += $$PWD/../app TEMPLATE = app TARGET = tst_example DISTFILES += \ tst_MoviePlayer.qml SOURCES += \ main.cpp
As you can see, I tried INCLUDEPATH, IMPORTPATH, and QML_IMPORT_PATH to point at the parent-directory/app folder where the custom component .qml is at.
The structure is like this:
|- MyProject.pro | - app |- main.qml |- main.pro |- main.cpp |- MoviePlayer.qml |- qml.qrc | - tests |- test.pro |- main.cpp |- tst_MoviePlayer.qml
When I go in tst_MoviePlayer.qml and try this:
TestCase { function test_MoviePlayer() { var moviePlayer = createTemporaryQmlObject("import MoviePlayer 1.0; MoviePlayer {}", this) } }
It says MoviePlayer module is not installed. I also tried just createTemporaryQmlObject("MoviePlayer {}", this) and get "MoviePlayer is not a type" error.
I added a .qrc file with the following structure and I was able to create a MoviePlayer type inside my tests qml files, however I still cannot createTemporaryQmlObject because it still says 'MoviePlayer is not a type' even though I can declare a MoviePlayer type just fine in the very same file?
<RCC> <qresource prefix="/"> <file>tst_MoviePlayer.qml</file> <file alias="MoviePlayer.qml">../app/MoviePlayer.qml</file> </qresource> </RCC>