Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

module "Qt.test.qtestroot" is not installed



  • Hi,
    I want to write a test for turn on LED.
    this is my code:
    import QtQuick 2.9
    import QtQuick.Controls 2.0
    import QtQuick.Window 2.2
    import QtTest 1.0

    Window {
    visible: true
    width: 300
    height: 100
    Rectangle {
    width: parent.width / 2
    height: parent.height
    color: "#73d216"
    Text {
    anchors.centerIn: parent
    text: "turn on"
    }
    MouseArea {
    anchors.fill: parent
    onClicked: {
    ts.turnOn();
    }
    }
    TestCase{
    name:"KeyClick"
    when:windowShown
    function test_key_click(){
    keyClick(Qt.Key_Left)
    keyClick("turn off")
    }
    }
    }
    }
    but when i want to run it on raspberry pi bellow error apear:
    module "Qt.test.qtestroot" is not installed
    Is there any solution for solve it?



  • Ok, I had the same issue and it was due to a general lack of understanding from the docs which I didn't know enough to really understand. My guess is you are using a mostly auto-generated .pro file, and I recommend deleting everything and just putting in:

    TEMPLATE = app
    TARGET = tst_example
    CONFIG += warn_on qmltestcase
    SOURCES += tst_example.cpp
    RESOURCES += qml.qrc

    This says that tst_example is the target, so also make a C++ file called tst_example.cpp and put in just these two lines:

    #include <QtQuickTest>
    QUICK_TEST_MAIN(example)

    Finally make a file called tst_test.qml and put in:

    import QtQuick 2.3
    import QtTest 1.0

    TestCase {
    name: "TestingTestCases"

    function test_math() {
        compare(2 + 2, 4, "2 + 2 = 4")
    }
    
    function test_fail() {
        compare(2 + 2, 4, "2 + 2 = 5")
    }
    

    }

    I got this from qt's example test case. Now run it and it should print the result of that test case. That should give you a model to go off of, the moral of the story is: no one understands how qmake works so read more docs lol, I'm still learning about them :).



  • I was also trying to follow documentation at
    https://doc.qt.io/qt-5/qtquicktest-index.html

    It is not clear how create tests next to production code. In C with libcheck I just add test case next to function it self. Then I compile two binaries: the application and the test runner. The test functions are enabled or disabled by preprocessor as needed.

    I was trying to create minimal application with such behavior, but I have same error message as you:

     module "Qt.test.qtestroot" is not installed
    

    Finally, I have found https://github.com/benlau/testable which probably does everything I need.


Log in to reply