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. How to structure QtTest project as qt's github shows and how to access tested classes
Forum Updated to NodeBB v4.3 + New Features

How to structure QtTest project as qt's github shows and how to access tested classes

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 387 Views 1 Watching
  • 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
    Grpt
    wrote on last edited by
    #1

    Hello,

    I have been struggling to implement QtTest on an existing Qt Project.
    I would like to test multiple classes. I made an auto-test project with multiple test_classes and then execute them, it works but the IDE Test Tool doesn't work at all. I can't select which tests I want to execute separately, on top of that if I select X files, it will execute all files X times (if I have 30 tests in 3 folders if I select 2 folders it will execute 60 tests).

    After many adventures, I found this topic saying that the correct method is to create one auto-test project for each class, and this is how it's done on qt's github. So I've tested this solution on a little sample, it worked well.
    But the problem is that, I want to implement this solution on a bigger project with a lot of classes, meaning that I have folders with classes and folders in them.
    How do I structure that ?

    Following qt's Github I have created a "sub-project" project which will contain all unit test projects.

    I encountered another problem, which is that I can't add a folder in a "subproject" project so I have all my tests as like following
    I tried to put the autotest projects in folders but it did not change anything.

    Subproject
         - Project
              - Charges
                   - Charge.h
                   - anotherFile.h
              - Structures
                   - file.h
                   - newFile.h
         - Test_Subproject
              - tst_charges_autoTestProject
                   - tst_charge.cpp
              - tst_anotherFile_autoTestProject
                   - tst_anotherFile.cpp
              - tst_structure_autoTestProject
                   - tst_structure.cpp
    

    What I want my file hierarchy to look like (same as on github)

         - Test_Subproject
              - Charges
                   - tst_charges_autoTestProject
                        - tst_charge.cpp
                   - tst_anothFile_autoTestProject
                        - tst_anothFile.cpp
              - Structure
                   - tst_structure_autoTestProject
                        - tst_structure.cpp
    

    But it raised another problem (again) How do I access the class I want to test from the tests classes ?
    Here is how I had access to the tested classes when I tried with all test_class.cpp/h in the same auto-test project

    SOURCES += \
        *.cpp \
        $$files(../cpp/*.cpp, true) \
    
    
    HEADERS += \
        *.h \
        $$files(../cpp/*.h, true) \
    
    
    INCLUDEPATH += \
        $$PWD \
        ../cpp/
    

    Accessing "charge.h" from "test_charge.h" for example

    #include <../cpp/Charges/charge.h>
    

    I tried something similar on my current project but it does not seem to work.
    To sum up I have 2 two questions

    1. How do I get a "good looking" hierarchy like mentionned above. Looking similar to the project src hierarchy.
    2. How do I access the class I want to test from the tests classes ?

    ‎
    I hope it is not too confusing if you need more information tell me. I will update this topic if I find something new.

    Important note : Unlike qt's github, I am not using cmake but qmake (with mingw)

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

      Hi,

      If you want to see the test structure of Qt using qmake, switch to the Qt 5.15 branch.

      If you want to follow Qt's structure (which is a good idea), have a test folder at the root of your project and then you can define the same structure as your main project.

      What would be done then is that your project code structure would be:

      • 1 subproject for your application
      • 1 or more subprojects that would be librairies that provide all the bits and pieces to create your application (GUI, business logic, etc)

      You application project would then essentially be a main.cpp file and link to the librairies.

      Then in your test you just have to point your test to include folders of the library they will be testing and link to said library.

      Doing it that way allows you to do unit testing, integration testing and application testing.

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

        Thanks for your answer, it helped me a lot :)

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

          You're welcome !

          Since that answers your question please mark the thread as solved using the "Topic Tools" button or the three dotted menu beside the answer that you deem correct so other forum users may know a solution has been found :-)

          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

          • Login

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