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 7801407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:56:31+00:00 2026-06-02T00:56:31+00:00

In our project we are using the QtTestLib for a unit testing. The reasons

  • 0

In our project we are using the QtTestLib for a unit testing. The reasons are that the whole project already uses Qt whenever it’s possible and it’s a GUI application, so we wanted to have ability for testing GUI interfaces.

Our project is compiled by the MSVC, so we didn’t want to have a separated project file for each test ‘coz it will clutter the solution. Thus we have created a single project for all tests. All testing should be automated on a CIS (continuous integration), so we tried to plug our tests to the Hudson through an output file in XML format using some XSLT transformations.

But it seems there is a problem with tests’ output. If you use a single main() for all tests and merely transmit cmd line arguments to each test:

#include "MyFirstTest.h"
#include "MySecondTest.h"

int main(int argc, char **argv)
{
  int result = 0;
  MyFirstTest test1;
  result |= QTest::qExec(&test1, argc, argv);
  MySecondTest test2;
  result |= QTest::qExec(&test2, argc, argv);
  return result;
}

then you will get a result file rewrited multiple times. So if you want to automate it somewhat using output file (xml for example), you’ll get only the last result in it. All other will be overwritten.

We have tried that approach already, it does not give you ability to use some continuous integration systems like Hudson. So my question will be: is there any opportunities to append results in one output file? Of course we can use some workarounds like running each test by QTest::qExec() with a modified parameters to write results in separate files, but it doesn’t seem to be the best way. Ideally I want to have a single result file to use it with CIS.

  • 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-02T00:56:32+00:00Added an answer on June 2, 2026 at 12:56 am

    With this trick you can collect the individual test xml reports to temporary buffers/files; all from a single test binary. Lets employ QProcess to collect separate test outputs from within one binary; the test calls itself with modified arguments. First, we introduce a special command-line argument that harnesses the subtests proper – all still within your test executable. For our convenience, we use the overloaded qExec function that accepts a QStringList. Then we can insert/remove our "-subtest" argument more easily.

    // Source code of "Test"
    
    int
    main( int argc, char** argv )
    {
      int result = 0;
    
      // The trick is to remove that argument before qExec can see it; As qExec could be
      // picky about an unknown argument, we have to filter the helper 
      // argument (below called -subtest) from argc/argc; 
    
      QStringList args;
    
      for( int i=0; i < argc; i++ )
      {
         args << argv[i];
      }
    
      // Only call tests when -subtest argument is given; that will usually
      // only happen through callSubtestAndStoreStdout
    
      // find and filter our -subtest argument
    
      size_t pos = args.indexOf( "-subtest" );
    
      QString subtestName;
    
      if( (-1 != pos) && (pos + 1 < args.length()) )
      {
        subtestName = args.at( pos+1 );
    
        // remove our special arg, as qExec likely confuses them with test methods
    
        args.removeAt( pos );
        args.removeAt( pos );
    
        if( subtestName == "test1" )
        {
          MyFirstTest test1;
          result |= QTest::qExec(&test1, args);
        }
    
        if( subtestName == "test2" )
        {
          MySecondTest test2;
          result |= QTest::qExec(&test2, args);
        }
    
        return result;
    }
    

    Then, in your script/commandline call:

    ./Test -subtest test1 -xml ... >test1.xml
    ./Test -subtest test2 -xml ... >test2.xml
    

    and here you are – we have the means to separate the tests output. Now we can continue to use QProcess’es ability to collect stdout for you. Just append these lines to your main. The idea is to call our executable again, if no explicit tests are requested, but with our special argument:

    bool
    callSubtestAndStoreStdout(const String& subtestId, const String& fileNameTestXml, QStringList args)
    {
       QProcess proc;
    
       args.pop_front();
    
       args.push_front( subtestId );
       args.push_front( "-subtest" );
    
       proc.setStandardOutputFile( fileNameTestXml );
    
       proc.start( "./Test", args );
    
       return proc.waitForFinished( 30000 ); // int msecs
    }
    
    int 
    main( int argc, char** argv )
    {
       .. copy code from main in box above..
    
       callSubtestAndStoreStdout("test1", "test1.xml", args);
       callSubtestAndStoreStdout("test2", "test2.xml", args);
    
       // ie. insert your code here to join the xml files to a single report
    
       return result;
    }
    

    Then in your script/commandline call:

    ./Test -xml           # will generate test1.xml, test2.xml
    

    Indeed, hopefully future QTestLib versions makes this easier to do.

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

Sidebar

Related Questions

Our project is using a nightly backup application that simply makes a duplicate of
Our issue is that our project has files being downloaded using wget to the
We are currently using unit tests to test our project. We have the majority
We have our project build using maven. We try to run our unit test
We're using Mono.Cecil in our project. Does it have any functionality that allows me
We are using GroovyFX in our project, to build our user interfaces. It already
Our project is using many static libraries to build the application. How can we
Ok so in our project I'm using System.Linq.Dynamic library but I just noticed that
Our project already has a StyleCop configuration. I am using ReSharper and I would
Our C/C++ project is using a new internal script that liberally wraps every function

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.