Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt Test
Qt 6.11 is out! See what's new in the release blog

Qt Test

Scheduled Pinned Locked Moved Solved QML and Qt Quick
13 Posts 2 Posters 1.9k 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.
  • KillerSmathK KillerSmath

    @JasmineSethi
    I suggest you to read the QtTest documentation.
    https://doc.qt.io/qt-5/qml-qttest-testcase.html

    Check out this example:
    Edit:
    "red" -> "#ff000"
    "yellow" -> "#ffff00"
    mouseClick(mouseArea) instead mouseArea.clicked()

    TestCase {
        name: "rectangleColor"
        when: windowShown
        function test_rectColor() {
            compare(b1.color, "#ff0000"); // check color
            mouseClick(mouseArea); // emit clicked signal
            compare(b1.color, "#ffff00"); // check color
        }
    }
    
    J Offline
    J Offline
    JasmineSethi
    wrote on last edited by JasmineSethi
    #3

    @KillerSmath Hi, Thanks for your previous response.

    I have another question.

    I have a function which is part of button.qml as shown below. I want to do qtest for this. How can i ?

    function setDisableState(disable)
    {
    properties.disableButton = disable
    //properties is part of QtObject.
    //i.e. property bool disableButton: false

        if(disable === true)
        {
            buttonAudioPause.color = properties.disableStateModern
            buttonAudioPause.border.color = properties.disableStateModern
            mainAudioPauseButton.enabled = false
            properties.btnTextColor =  properties.modernGray4
        }
    
        else if(disable === false)
        {
            buttonAudioPause.color =  properties.buttonColor
            buttonAudioPause.border.color = properties.buttonColor
            mainAudioPauseButton.enabled = true
            properties.btnTextColor =  properties.blackColor
    
        }
    
    }
    
    KillerSmathK 1 Reply Last reply
    0
    • J JasmineSethi

      @KillerSmath Hi, Thanks for your previous response.

      I have another question.

      I have a function which is part of button.qml as shown below. I want to do qtest for this. How can i ?

      function setDisableState(disable)
      {
      properties.disableButton = disable
      //properties is part of QtObject.
      //i.e. property bool disableButton: false

          if(disable === true)
          {
              buttonAudioPause.color = properties.disableStateModern
              buttonAudioPause.border.color = properties.disableStateModern
              mainAudioPauseButton.enabled = false
              properties.btnTextColor =  properties.modernGray4
          }
      
          else if(disable === false)
          {
              buttonAudioPause.color =  properties.buttonColor
              buttonAudioPause.border.color = properties.buttonColor
              mainAudioPauseButton.enabled = true
              properties.btnTextColor =  properties.blackColor
      
          }
      
      }
      
      KillerSmathK Offline
      KillerSmathK Offline
      KillerSmath
      wrote on last edited by
      #4

      @JasmineSethi
      You can call the function using the object identifier buttonAudioPause.setDisableState(true) and check if the variable has been changed using compare calls.

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      J 1 Reply Last reply
      0
      • KillerSmathK KillerSmath

        @JasmineSethi
        You can call the function using the object identifier buttonAudioPause.setDisableState(true) and check if the variable has been changed using compare calls.

        J Offline
        J Offline
        JasmineSethi
        wrote on last edited by
        #5

        @KillerSmath

        I wrote 2 function set() and get()
        function setDisableState(disable)
        {
        properties.disableButton = disable

            if(disable === true)
            {
                buttonAudioPause.color = "some color value"
                buttonAudioPause.border.color = "some color value"
                mainAudioPauseButton.enabled = false
                properties.btnTextColor =  "some color value"
            }
        
            else if(disable === false)
            {
                buttonAudioPause.color =  "some color value"
                buttonAudioPause.border.color ="some color value" 
                mainAudioPauseButton.enabled = true
                properties.btnTextColor =  "some color value"
        
            }
        
        }
        function getDisableState(disable)
        {
            return properties.disableButton
        }
        

        My TestCase looks something like this:

        I am instantiating qml file and using its id to call the set() and get() function.

        RSBB_ButtonWidget_AudioPause
        {
        id: rsbbAudioPauseButton

        }
        

        TestCase
        {
        name: "Disable state"
        when: windowShown

            function test_disableStateForAudioPauseButton()
            {
                rsbbAudioPauseButton.setDisableState(true)
                compare(rsbbAudioPauseButton.getDisableState(),?,?)//??
        
            }
        }
        

        //My question is how to test more than one condition(for example buttonAudioPause.color, buttonAudioPause.border.color) in "compare" statement when setDisableState(true) and setDisableState(false) ?

        KillerSmathK 1 Reply Last reply
        0
        • J JasmineSethi

          @KillerSmath

          I wrote 2 function set() and get()
          function setDisableState(disable)
          {
          properties.disableButton = disable

              if(disable === true)
              {
                  buttonAudioPause.color = "some color value"
                  buttonAudioPause.border.color = "some color value"
                  mainAudioPauseButton.enabled = false
                  properties.btnTextColor =  "some color value"
              }
          
              else if(disable === false)
              {
                  buttonAudioPause.color =  "some color value"
                  buttonAudioPause.border.color ="some color value" 
                  mainAudioPauseButton.enabled = true
                  properties.btnTextColor =  "some color value"
          
              }
          
          }
          function getDisableState(disable)
          {
              return properties.disableButton
          }
          

          My TestCase looks something like this:

          I am instantiating qml file and using its id to call the set() and get() function.

          RSBB_ButtonWidget_AudioPause
          {
          id: rsbbAudioPauseButton

          }
          

          TestCase
          {
          name: "Disable state"
          when: windowShown

              function test_disableStateForAudioPauseButton()
              {
                  rsbbAudioPauseButton.setDisableState(true)
                  compare(rsbbAudioPauseButton.getDisableState(),?,?)//??
          
              }
          }
          

          //My question is how to test more than one condition(for example buttonAudioPause.color, buttonAudioPause.border.color) in "compare" statement when setDisableState(true) and setDisableState(false) ?

          KillerSmathK Offline
          KillerSmathK Offline
          KillerSmath
          wrote on last edited by KillerSmath
          #6

          @JasmineSethi
          Compare function only compares pairs of data.
          However, it may be generalize using object comparison.

          {
            key_1: value_1, 
            key_2: value_2
          }
          

          So, you can return a object with button states and compare with an expected result. Here is a example.

          function getDisableState()
          {
              return {
                  enabled: yourButtonID.enabled, 
                  color: yourButtonID.color
              }
          }
          // your code
          TestCase 
          { 
              function test_disableStateForAudioPauseButton()
              {
                  yourButtonID.setDisableState(true)
                  compare(yourButtonID.getDisableState(), {enabled: false, color: "some color value"})
              }
          }
          

          @Computer Science Student - Brazil
          Web Developer and Researcher
          “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

          J 1 Reply Last reply
          0
          • KillerSmathK KillerSmath

            @JasmineSethi
            Compare function only compares pairs of data.
            However, it may be generalize using object comparison.

            {
              key_1: value_1, 
              key_2: value_2
            }
            

            So, you can return a object with button states and compare with an expected result. Here is a example.

            function getDisableState()
            {
                return {
                    enabled: yourButtonID.enabled, 
                    color: yourButtonID.color
                }
            }
            // your code
            TestCase 
            { 
                function test_disableStateForAudioPauseButton()
                {
                    yourButtonID.setDisableState(true)
                    compare(yourButtonID.getDisableState(), {enabled: false, color: "some color value"})
                }
            }
            
            J Offline
            J Offline
            JasmineSethi
            wrote on last edited by
            #7

            @KillerSmath

            Not able to return more than one object as shown neither this nor the way u mentioned.

            0_1556098759055_f95d93cb-117e-4114-8923-e9a6d9778f66-image.png

            KillerSmathK 1 Reply Last reply
            0
            • J JasmineSethi

              @KillerSmath

              Not able to return more than one object as shown neither this nor the way u mentioned.

              0_1556098759055_f95d93cb-117e-4114-8923-e9a6d9778f66-image.png

              KillerSmathK Offline
              KillerSmathK Offline
              KillerSmath
              wrote on last edited by
              #8

              @JasmineSethi said in Qt Test:

              @KillerSmath

              Not able to return more than one object as shown neither this nor the way u mentioned.

              0_1556098759055_f95d93cb-117e-4114-8923-e9a6d9778f66-image.png

              I have mentioned this structure:

              {
                key_1: value_1, 
                key_2: value_2
              }
              

              @Computer Science Student - Brazil
              Web Developer and Researcher
              “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

              J 1 Reply Last reply
              0
              • KillerSmathK KillerSmath

                @JasmineSethi said in Qt Test:

                @KillerSmath

                Not able to return more than one object as shown neither this nor the way u mentioned.

                0_1556098759055_f95d93cb-117e-4114-8923-e9a6d9778f66-image.png

                I have mentioned this structure:

                {
                  key_1: value_1, 
                  key_2: value_2
                }
                
                J Offline
                J Offline
                JasmineSethi
                wrote on last edited by
                #9

                @KillerSmath

                Tried the same way too. It didn't worked
                0_1556099468270_26dd44cf-dd4a-41a0-8c06-8bcc0c268a0b-image.png

                KillerSmathK 1 Reply Last reply
                0
                • J JasmineSethi

                  @KillerSmath

                  Tried the same way too. It didn't worked
                  0_1556099468270_26dd44cf-dd4a-41a0-8c06-8bcc0c268a0b-image.png

                  KillerSmathK Offline
                  KillerSmathK Offline
                  KillerSmath
                  wrote on last edited by
                  #10

                  @JasmineSethi
                  A explanation about why it is happening.
                  https://stackoverflow.com/questions/18221963/javascript-function-fails-to-return-object-when-there-is-a-line-break-between-th

                  @Computer Science Student - Brazil
                  Web Developer and Researcher
                  “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

                  J 1 Reply Last reply
                  0
                  • KillerSmathK KillerSmath

                    @JasmineSethi
                    A explanation about why it is happening.
                    https://stackoverflow.com/questions/18221963/javascript-function-fails-to-return-object-when-there-is-a-line-break-between-th

                    J Offline
                    J Offline
                    JasmineSethi
                    wrote on last edited by
                    #11

                    @KillerSmath
                    Yeah i went through this link. Then i think its not a good practice to keep the return statement for more than one line. Then wt's the best solution to do qt test for the problem i stated? Any idea?

                    KillerSmathK 1 Reply Last reply
                    0
                    • J JasmineSethi

                      @KillerSmath
                      Yeah i went through this link. Then i think its not a good practice to keep the return statement for more than one line. Then wt's the best solution to do qt test for the problem i stated? Any idea?

                      KillerSmathK Offline
                      KillerSmathK Offline
                      KillerSmath
                      wrote on last edited by KillerSmath
                      #12

                      @JasmineSethi
                      You could call the change function and test each property with individual compare calls. And btw, it is better than using an object, because in the case of object, the error output will print "Object is different of Object".
                      but using the unique property, the value of the properties will be printed, facilitating the diagnosis.

                      @Computer Science Student - Brazil
                      Web Developer and Researcher
                      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

                      J 1 Reply Last reply
                      0
                      • KillerSmathK KillerSmath

                        @JasmineSethi
                        You could call the change function and test each property with individual compare calls. And btw, it is better than using an object, because in the case of object, the error output will print "Object is different of Object".
                        but using the unique property, the value of the properties will be printed, facilitating the diagnosis.

                        J Offline
                        J Offline
                        JasmineSethi
                        wrote on last edited by JasmineSethi
                        #13

                        @KillerSmath
                        Hi,
                        I took an array and kept all the properties like :
                        property variant getdisablearray: [buttonAudioPause.color,
                        buttonAudioPause.border.color, mainAudioPauseButton.enabled, properties.btnTextColor]

                        In get() returned this array
                        function getDisableState()
                        {
                        return properties.getdisablearray
                        }

                        //Test case looks like below:
                        property variant abc:[]

                        TestCase
                        {
                            name: "Disable state for audio pause"
                            when: windowShown
                        
                            function test_disableStateForAudioPauseButton()
                            {
                                rsbbAudioPauseButton.setDisableState(true)
                                abc = rsbbAudioPauseButton.getDisableState()  
                                compare(abc[0],"#17202a","test not pass")
                                compare(abc[1],"#17202a","test not pass")
                                compare(abc[2],false,"test not pass")
                                compare(abc[3],"#666666","test not pass")
                        
                            }
                        }
                        
                        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