Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. UnitTest sinnvoll einsetzen

UnitTest sinnvoll einsetzen

Scheduled Pinned Locked Moved Unsolved German
3 Posts 1 Posters 606 Views
  • 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 Offline
    G Offline
    Galilio
    wrote on last edited by Galilio
    #1

    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
    0
    • G Offline
      G Offline
      Galilio
      wrote on last edited by
      #2

      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
      0
      • G Offline
        G Offline
        Galilio
        wrote on last edited by
        #3

        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
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved