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. QtTest - Share your workflow

QtTest - Share your workflow

Scheduled Pinned Locked Moved Unsolved General and Desktop
testingqttestunit-testing
5 Posts 2 Posters 584 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.
  • U Offline
    U Offline
    uod_
    wrote on 12 Oct 2022, 13:51 last edited by uod_ 10 Dec 2022, 13:54
    #1

    Hi, I would like to see other developers' workflow and settings when using QtTest. Please, try to explain your reasoning as well if you think it can help others.

    1. How do you structure your project? (Folder structure, Qmake, CMake settings, etc)

    2. What are you testing? (Do you test Qt modules, elements, your own libraries, 3rd party libraries, only unit testing or testing high-level GUI functions, etc ..)

    3. How do you deal with other interfaces? (Local database, remote server, hardware, mock hardware, etc)

    4. What do you put in constructor, destructor, init(), cleanup(), initTestCase(), and cleanUpTestCase()?
      (ex: "I open database then create tables at init()", "I use setApplicationName("myApp") within constructor" ...)

    5. Besides general good testing practices, is there any framework, or tips, you follow?

    6. Is there any Qt-specific testing tips you have for other developers?

    Thanks for your time in advance.

    edit: miswriting

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 12 Oct 2022, 19:01 last edited by
      #2

      Hi and welcome to devnet,

      Your post sounds almost like a survey. Is it one ?

      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
      • U Offline
        U Offline
        uod_
        wrote on 17 Oct 2022, 12:05 last edited by
        #3

        Hey, thanks a lot.

        I didn't mean it to be a survey, I wanted to copy the good practices of other developers who are more experienced with Qt. The Internet has many resources to be used as guidelines when it comes to testing, but I wanted to see more concrete examples. While working with Qt I figured I should tailor my unit tests to utilize Qt when I can. This is why I wanted to ask people about their experiences.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 18 Oct 2022, 19:41 last edited by
          #4

          You can pick up ideas from the Qt source tree itself.

          That said one possible nice architecture:

          • use sub-projects
            • one or more libraries for your business and widget logic
            • each is again a sub-project based project where you have all the required tests in a dedicated folder (which is again based on the sub-project template)
            • one application project that puts together the core widgets of your application. Basically this project is usually just a ˋmain.cpp` file that loads your main widget and do some initialization stuff if needed.

          So all your tests are close to the code they are ensuring works correctly.

          You can have tests at various levels to ensure that you library code is doing what is expected, then upper that the code using these libraries are also working as expected etc.

          Don't do low-level tests at a higher level. For example, testing that a widget acts correctly to answers from a device on a serial port does mean that you have to run these tests for every possible configurations of the serial port.

          The example above is also a good candidate for mocking. When testing, you typically don't have a device at hand connected to your CI (it might possible but not always) hence the importance of writing your code so that you can replace the serial device with a "virtual device" for your tests. Typically, rather than have an internal QSerialPort, you should have the controller class that accepts a configured QIODevice and use it's interface, that way, when testing you can pass a mock device.

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

          U 1 Reply Last reply 19 Oct 2022, 11:58
          1
          • S SGaist
            18 Oct 2022, 19:41

            You can pick up ideas from the Qt source tree itself.

            That said one possible nice architecture:

            • use sub-projects
              • one or more libraries for your business and widget logic
              • each is again a sub-project based project where you have all the required tests in a dedicated folder (which is again based on the sub-project template)
              • one application project that puts together the core widgets of your application. Basically this project is usually just a ˋmain.cpp` file that loads your main widget and do some initialization stuff if needed.

            So all your tests are close to the code they are ensuring works correctly.

            You can have tests at various levels to ensure that you library code is doing what is expected, then upper that the code using these libraries are also working as expected etc.

            Don't do low-level tests at a higher level. For example, testing that a widget acts correctly to answers from a device on a serial port does mean that you have to run these tests for every possible configurations of the serial port.

            The example above is also a good candidate for mocking. When testing, you typically don't have a device at hand connected to your CI (it might possible but not always) hence the importance of writing your code so that you can replace the serial device with a "virtual device" for your tests. Typically, rather than have an internal QSerialPort, you should have the controller class that accepts a configured QIODevice and use it's interface, that way, when testing you can pass a mock device.

            U Offline
            U Offline
            uod_
            wrote on 19 Oct 2022, 11:58 last edited by
            #5

            @SGaist Thank you for taking the time. Now, I am happy that I've more or less applied the architecture and workflow suggested by the man himself already. The example you used toward the end is exactly my case, which leads me to ask for tips here.

            I will be checking the source tree for more specific cases and will be making modifications accordingly.

            1 Reply Last reply
            0

            4/5

            18 Oct 2022, 19:41

            • Login

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