-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
None
Consider a test case:
TestCase {
id: testCase
name: "TrailTest"
function initTestCase() {
}
function cleanupTestCase() {
}
Rectangle {
id: rectangle
color: Qt.rgba(1, 0, 0, 1)
width: 100
height: 100
}
function test_saveImage() {
let image = grabImage(rectangle)
compare(image.pixel(0, 0), Qt.rgba(1, 0, 0, 1));
}
}
which results in
QML debugging is enabled. Only use this in a safe environment.
********* Start testing of example *********
Config: Using QtTest library 6.10.0, Qt 6.10.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 11.4.1 20231218 (Red Hat 11.4.1-3)), ubuntu 22.04
PASS : example::TrailTest::initTestCase()
FAIL! : example::TrailTest::test_saveImage() Compared values are not the same
Actual (): #ffffff
Expected (): #ff0000
Loc: [/home/luchen/Documents/QtProjects/QuickTestPlayground/tst_trailtest.qml(23)]
PASS : example::TrailTest::cleanupTestCase()
Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted, 87ms
********* Finished testing of example *********
We explicitly requested a red Rectangle but test failed because it was considered to be white. The reason is that the direct parent of Rectangle, i.e. the TestCase, is not visible.
So I think there should be some records in TestCase about the following things:
1. TestCase is by default invisible. If user wants to test something "visual", they need to explicitly set "visible" true". Or in the opposite way: we make TestCase visible by default (what stops us from doing that though?).
2. There is "windowShown" property, yes. But it does not necessarily mean that the item of interest is visible. In the example above, one can add "when: windowShown" to TestCase and confirm by "compare(testCase.windowShown, true)". Even though, it does not make any difference. Test still fails when window is shown. Property "visible" is the key.
3. The containing Window of TestCase has its default size 200x200. When TestCase has explicit size, the containing Window is sized to it. User may also find this behavior useful.