Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Unsolved UnitTest sinnvoll einsetzen

    German
    1
    3
    222
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      Galilio last edited by Galilio

      Hallo zusammen,

      ich habe folgende QML Datei:

      Item {
      	id :rootId
      	property string iconImage: ""
      	property string headerText: "Header Not specified"
      	property bool display_helpButton: true
      	property bool display_header: true
      	.....
      	
      	
      	
      	Rectangle {
      		anchors.fill: parent
      		color: windowsFrame_color
      		Rectangle{
      			width: tabsWidth
      			height: parent.height
      			color: windowsFrame_headerColor
      			visible:rootId.tabBarorientation === ListView.Horizontal ? false:true
      		}
      	}
      	Rectangle {
      		id: headingTopBarId
      		anchors.left: parent.left
      		....
      		Image {
      			id: iconImage
      			visible:true
      			x:iconPosX
      			y:iconPosY
      			width:....
      			...
      		}
      		Text {
      			....
      		}
      	}
      	ListView {
      		id: lisViewId
      		...
      		
      		
      	}
      }
      

      Für diese QML Datei, möchte ich einen UnitTest schreiben.
      Meine Frage ist:
      Wie soll ich den UnitTest am besten gestalten?
      Soll ich alle Childern testen?
      Wenn es so ist, dann muss ich alle childern mit ObjectName versehen, damit sie getestet werden können.

      Danke in voraus

      1 Reply Last reply Reply Quote 0
      • G
        Galilio last edited by

        Hello zusammen,

        ich habe für die folgende QML Abschnitt einen Unittest erfasst:

        Image {
        	id: iconImageId
        	objectName: "imageId"
        
        	visible: true
        	y: iconPosY
        	x: iconPosX
        
        	width:  headerIconWidth
        	height: headerIconHeight
        
        	fillMode: Image.PreserveAspectFit
        	clip: true
        	asynchronous: true
        	source: rootId.iconImage
        	states: [
        		State {
        			name: "loaded"
        			when: iconImageId.status == Image.Loading
        	   }
        	]
        }
        

        Der cpp file sieht dann so aus:

        void ut_QQtTest::test_image()
        {
            Q_ASSERT(mTestItem);
            mTestItem->setProperty("iconImage", "test.png");
            mHeader = mTestItem->findChild<QQuickItem*>("header");
            Q_ASSERT(mHeader);
        
            mImage = mHeader->findChild<QQuickItem*>("imageId");
            Q_ASSERT(mImage);
            // Check Image property
            QCOMPARE(mImage->property("visible").toBool(), true );
            QCOMPARE(mImage->property("x").toDouble(), 500.0 );
            QCOMPARE(mImage->property("y").toDouble(), 20.0 );
            QCOMPARE(mImage->property("width").toDouble(), 45.0 );
            QCOMPARE(mImage->property("height").toDouble(), 45.0 );
            QCOMPARE(mImage->property("clip").toBool(), true );
            QCOMPARE(mImage->property("asynchronous").toBool(), true );
            QCOMPARE(mImage->property("fillMode").toInt(), 1);
            qDebug() << "state" <<mImage->property("state").toString();
            QCOMPARE(mImage->property("state").toString(), QString("loaded"));
            qDebug() << "Status" << mImage->property("status").toInt();
            QCOMPARE(mImage->property("status").toInt(), 2);
        }
        

        Bei Starten crashed der Unittest.
        Mir ist nicht ganz klar worauf soll ich achten beim Image Unittest?

        1 Reply Last reply Reply Quote 0
        • G
          Galilio last edited by

          Das UnitTest crashed nicht wenn ich so schreibe:
          mTestItem->setProperty("iconImage", "");

          Hat das vielleicht mit dem Casten zu tun?

          übrigen das "iconImage" ist auf die QMl Seite als string definiert

          1 Reply Last reply Reply Quote 0
          • First post
            Last post