I am very new to Qt and Qt Quick. I am validating the Qt Test unit testing framework for Qt Quick and I am not able to understand how to run the tests. Here's what I have, I have created a SUBDIRS project with the following structure:
ProjectSolution
ProjectSolution.pro
Project
Project.pro
Sources/main.cpp
Resources/qml.qrc/main.qml
ProjectTest
ProjectTest.pro
Sources/main.cpp
Resources/qml.qrc/main.qml
Resources/qml.qrc/tst_gui.qml
"Project" is the application to be tested and my test cases are in "ProjectTest/Resources/qml.qrc/tst_gui.qml".
tst_gui.qml:
import QtQuick 2.5
import QtTest 1.0
TestCase {
name: "UI Testcase"
when: windowShown
function test_button_click() {
mouseClick(click_button, Qt.LeftButton, Qt.NoModifier)
}
function test_key_press() {
keyClick(Qt.Key_Left)
keyClick("a")
}
}
I have a Button with id "click_button" in "Project/Resources/qml.qrc/main.qml" that I want to simulate. When I run the test project, I get failure with message:
FAIL! : tst_gui::UI Testcase::test_button_click() Uncaught exception: click_button is not defined
C:\Users\sjayaprakash\Qt Test Projects\Qt Test Validation\QtTestValidation6\QtTestValidation6Test\tst_gui.qml(9) : failure location
I am sure I am doing something wrong. Could someone please help?