Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Unit Test Coverage] How can the industry improve QT code coverage
Forum Update on Monday, May 27th 2025

[Unit Test Coverage] How can the industry improve QT code coverage

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 183 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.
  • X Offline
    X Offline
    xurongqin
    wrote on last edited by
    #1

    Hello everyone, I am a C++ QT application engineer in the industry.

    After nearly 10 years of iteration, our products are facing the problem of lower and lower code unit test coverage. Low code unit test coverage is very detrimental to code quality and product quality.

    So we have been looking for ways to improve QT code unit test coverage or some guiding principles.

    I would like to ask the experts in the industry whether you can provide some experience to guide us to improve QT code unit test coverage?

    Thank u if u can share us some ideas!
    alt text

    jsulmJ 1 Reply Last reply
    0
    • X xurongqin

      Hello everyone, I am a C++ QT application engineer in the industry.

      After nearly 10 years of iteration, our products are facing the problem of lower and lower code unit test coverage. Low code unit test coverage is very detrimental to code quality and product quality.

      So we have been looking for ways to improve QT code unit test coverage or some guiding principles.

      I would like to ask the experts in the industry whether you can provide some experience to guide us to improve QT code unit test coverage?

      Thank u if u can share us some ideas!
      alt text

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @xurongqin Not clear to me: do you want to test Qt code or the code of your application?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xurongqin
        wrote on last edited by
        #3

        @jsulm , Thanks for your kind reply, I want to test the code of my application. My purpose is want to know how QT developers improve the unit test coverage on their application. Are there any rules or unit test frameworks that can help to guide us to improve the unit test coverage?

        Thank you so much

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote last edited by
          #4

          Hi and welcome to devnet,

          For testing frameworks, Qt already provides the QTest module which works pretty nicely.

          As for the rules, there's mainly one: test both happy and unhappy code paths. That way you ensure that your code is working when everything goes well as well as when issue arise.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xurongqin
            wrote last edited by xurongqin
            #5

            Hi @SGaist , Thanks so much for your reply. You advice seems interesting and is useful for us.

            Now we have a complete QTest framework in out QT application. But R&D found it was hard to write the UT since they sometimes felt that it was not smooth enough to cover all of the classes. The root cause might be from bad code design or something else. After we analyzed out QT application, we found that refactor the code by the MVC (Model-Viewer-Controller) design to decouple the classes might be also a possible way to help the R&D to write the unit test coding since some classes did not well follow the MVC design.

            If you have more detailed idea on it, pls share more information with us.

            jsulmJ S 2 Replies Last reply
            0
            • X xurongqin

              Hi @SGaist , Thanks so much for your reply. You advice seems interesting and is useful for us.

              Now we have a complete QTest framework in out QT application. But R&D found it was hard to write the UT since they sometimes felt that it was not smooth enough to cover all of the classes. The root cause might be from bad code design or something else. After we analyzed out QT application, we found that refactor the code by the MVC (Model-Viewer-Controller) design to decouple the classes might be also a possible way to help the R&D to write the unit test coding since some classes did not well follow the MVC design.

              If you have more detailed idea on it, pls share more information with us.

              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote last edited by
              #6

              @xurongqin said in [Unit Test Coverage] How can the industry improve QT code coverage:

              pls share more information with us

              What exactly do you need?
              MVC with Qt is documented here: https://doc.qt.io/qt-6/model-view-programming.html

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • X xurongqin

                Hi @SGaist , Thanks so much for your reply. You advice seems interesting and is useful for us.

                Now we have a complete QTest framework in out QT application. But R&D found it was hard to write the UT since they sometimes felt that it was not smooth enough to cover all of the classes. The root cause might be from bad code design or something else. After we analyzed out QT application, we found that refactor the code by the MVC (Model-Viewer-Controller) design to decouple the classes might be also a possible way to help the R&D to write the unit test coding since some classes did not well follow the MVC design.

                If you have more detailed idea on it, pls share more information with us.

                S Offline
                S Offline
                SimonSchroeder
                wrote last edited by
                #7

                @xurongqin It is really useful if the model is entirely separate from the view and controller. The model holds the data and acts on the data. Every functionality could just be tested on the model, no viewer or controller needed. Testing the view and controller would then just mean to test if the GUI triggers the appropriate actions inside the model (you might even just mock the model to check if the correct functions are called, already knowing from testing the model that it works). I'm not sure if testing the view appart from the controller makes sense. The view should just show things and the controller actually connects the view to the model (i.e. allows the GUI to trigger actions). A lot of times, with Qt view and controller are not necessarily separate anyway (I write constructors that create widgets, puts them inside a layout and then does the connects–this would be mixing the view (widgets+layouts) with the controller (connects)).

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SamiV123
                  wrote last edited by
                  #8

                  Best strategy is to design your application from the get go to be testable.

                  When designing Every class, every module, every component you should think "how do I make this testable". The good news when you make things "testable" you also get other "abilities" for free since highly testable components are also a) independent and decoupled b) have high cohesion and simple dependencies c) reusable d) have a coherent API c) have better thought out errors and bug conditions, invariants and pre/post conditions.

                  Then you test your components using whatever (unit) testing framework you like.

                  For UI testing you can also use some UI testing tools such as cucumber or other similar tools

                  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