Quantcast
Channel: Active questions tagged qtquick2 - Stack Overflow
Viewing all articles
Browse latest Browse all 132

QML TestCase not triggering with my component: What am I missing?

$
0
0

I created a component and decided to immediately add a TestCase to it to check when the application is launched, but the application does not start and even more so does not run.

My file is called SomeComponentsTest.qml

import QtQuick 2.11import QtQuick.Controls 2.4import QtTest 1.2Rectangle {    id: root    color: "yellow"    width: 200    height: 200    radius: 5    signal clicked    property int value: 0    onClicked: {        root.value++;    }    Label {        id: label        objectName: "label"        anchors.centerIn: parent        font.pixelSize: 24        color: "black"        text: root.value;    }    MouseArea {        id: mouseArea        objectName: "mouseArea"        anchors.fill: parent        onClicked: {            root.clicked();        }    }    TestCase {        name: "SomeComponentTests"        function test_color() {            compare(root.color, "yellow")            root.color = "#008000";            compare(root.color, "#008000")        }        function test_size() {            compare(root.width, 200)            compare(root.height, 200)        }        function test_label() {            compare(label.font.pixelSize, 24);            label.font.pixelSize = 44;            compare(label.font.pixelSize, 44);        }    }}

Yes, I know that for tests the prefix should be tst_*.qmlBut I have a dissonance in my head when I read the documentation, there is such an example:

Rectangle {    width: 640; height: 480    MultiPointTouchArea {        id: area        anchors.fill: parent        property bool touched: false        onPressed: touched = true    }    TestCase {        name: "ItemTests"        when: windowShown        id: test1        function test_touch() {            let touch = touchEvent(area);            touch.press(0, area, 10, 10);            touch.commit();            verify(area.touched);        }    }}

where for some reason a Rectangle is created before TestCase and I suppose that it is still possible to somehow run TestCase without the tst_*.qml prefix.

Do you know anything about this?


Viewing all articles
Browse latest Browse all 132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>