QML Testcases



  • Hi,
    I am trying to write QML testcases. I have a tab bar component and on its OnCompleted() I am creating tab buttons inside the Tab Bar dynamically.
    I want to write a test case to check if the correct number of tab buttons are created. In testcase I have written when : tabBarButtonsCreated and I am emitting that signal after the createTabBarButtons(), but the count is returning 0. But console.log there is showing the right number.

    import "../JS/TabButtonCreator.js" as TabButtonCreator 
    signal tabButtonsCreated
    TabBar {
     id: tabbarGroup
       Component.onCompleted: {
                TabButtonCreator.createTabButtons() 
               console. log("tab btn count:", tabbarGroup.count) // showing correct count
                tabButtonsCreated()
            }
    }
    

    In JS file :

    function createTabButtons() {
    tabButtonComponent = Qt.createComponent("qrc:/tabBtn.qml")
    
    }
    
    function finishCreation() {
    tabBtn = tabButtonComponent.createObject(tabbarGroup);
    }
    

    In TestCase file :

      TabBarComponent {
        id: tabBarComp
      }
        TestCase {
            name: "Check number of tab comonents"
            when: tabBarComp.tabButtonsCreated
            function test_tabComponentSize_check() {
                compare(tabBarComp.count, 4) // fails
            }
        }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.