Good day to all, I just recently started using unit tests when developing on Qt, but a question appeared: How to add tests to a project without causing confusion?

I add tests through the context menu "File" -> "New File or Project ..." - "Other Project" -> "Qt Unit Test". As a result, I create a separate project with one test (I learned from an article in Habré that this is a Qt approach to testing). But as the project grows, a huge number of tests are added, which bring chaos into the folder structure. I tried to create a folder for tests in the current project and put all the tests there, but I don’t know how to run all the unit tests at once when compiling.

And still, could you throw tutorials on unit testing on Qt (preferably in Russian)?

    1 answer 1

    A huge number of tests - this in itself is not bad. Split them into directories if you don’t like their aggregation in one place.

    A separate executable file for each test is one of the possible options. Another option is to run several tests at once, something like this (for good, you must also return a non-zero code if one of the tests fails):

    int main(int argc, char *argv[]) { TestFoo testFoo; QTest::qExec(&testFoo); TestBar testBar; QTest::qExec(&testBar); TestBaz testBaz; QTest::qExec(&testBaz); return 0; } 
    • Is it possible to make all tests run at the time of the project build? And how to make Qt understand how the layout of my tests is organized? Your example seems cumbersome to me, because tests will have to be stuffed into the main-function of the main project. For me, somehow it is not logical that the tests will be inside the program. - RareScrap
    • This is the main for the executable test file (not for the main application). As an example, in one executable file you can run several tests. - Vladimir Gamalyan