Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8534537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:13:10+00:00 2026-06-11T10:13:10+00:00

I have a Qt Unit test (sub)project, which generates me one class (with the

  • 0

I have a Qt Unit test (sub)project, which generates me one class (with the main generated by QTEST_APPLESS_MAIN).I can start this from within Qt Creator as console app.

Q: How would I add additional classes as test cases to this particular project.

  1. If these classes only have “test” slots (private Q_SLOTS), the methods are not called, but just the ones of the class with QTEST_APPLESS_MAIN
  2. Since there can be only one main(..), I cannot use QTEST_APPLESS_MAIN with more than one class in the project (is that correct?)
  3. Of course, I can manually “wire” the slots in the (additional) classes with the one class containing the main, but this is very tedious.

So what is the best way to run unit test over several classes in a unit test project?

PS:
In ” Using QT Unit Tests in a project – conflicting main(…) functions ” a Blog is mentioned, however, I cannot download the zip describing the solution.

Qt Unit Test subproject

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:13:11+00:00Added an answer on June 11, 2026 at 10:13 am

    As per the solution you linked to, the way to accomplish testing two (or more) classes within a single Qt unit test project is to ensure that each class to be tested has a corresponding test class, and that you’ve created a custom int main that executes each test class.

    For example:

    class TestClassA : public QObject
    {
       Q_OBJECT
    public:
       TestClassA();
    
       ...
    
    private Q_SLOTS:
       void testCase1();
       ...
    };
    
    class TestClassB : public QObject
    {
       Q_OBJECT
    public:
       TestClassB();
    
       ...
    
    private Q_SLOTS:
       void testCase2();
       ...
    };
    
    void TestClassA::testCase1()
    {
       // Define test here.
    }
    
    void TestClassB::testCase2()
    {
       // Define test here.
    }
    
    // Additional tests defined here.
    
    // Note: This is equivalent to QTEST_APPLESS_MAIN for multiple test classes.
    int main(int argc, char** argv)
    {
       int status = 0;
       {
          TestClassA tc;
          status |= QTest::qExec(&tc, argc, argv);
       }
       {
          TestClassB tc;
          status |= QTest::qExec(&tc, argc, argv);
       }
       return status;
    }
    

    Obviously, the different test classes can be spread out over multiple translation units, then simply included in the translation unit with your int main. Don’t forget to include the appropriate .moc files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Unit test project for my Application using DUnit framework. This project
I have a unit test that tests if an Exception is throw, but this
I have a unit test project based on UnitTest++. I usually put a breakpoint
I have a unit test project in Visual Studio 2010 (.NET 4) that utilizes
We have our project build using maven. We try to run our unit test
I have project in which I want to use check library for unit testing.
I have a unit test that can spontaneously fail 1 in 1,000,000 (guesstimation) times
I have a unit test to test one of my model classes and I
I have a unit test method which tests a controller action method. The action
I have a unit test (example is modified Test::Unit documentation ) require 'test/unit' class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.