Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for XML options #5

Open
e-j opened this issue May 6, 2015 · 1 comment
Open

Better support for XML options #5

e-j opened this issue May 6, 2015 · 1 comment

Comments

@e-j
Copy link
Owner

e-j commented May 6, 2015

The XML options of Qt Test library is a major feature for integration with external tools.

It can be used for produce test log that will be then be parse by IDE ( Eclipse Unit Tests runner) or continuous integration ( Jenkins XUnit)

As is with the actual MultiTest, those integration need an extra scripting phase for :

  1. Create a single consistent XML output.
  2. Save to different files each cases result

Note that other options provides by Qt Test Lib ( lightxml and xunitxml) should be concerned too.

Consistent single file

The purpose will be to have a single consistent XML file that cover all test suite.
Each case have a section.

I've experiment that it's possible to produce a similar file in few steps from the output of current MultiTest runner with the -xml option

  1. Create a top level <TestCase name=testSuite> XML element
  2. For all cases remove XML header and output them are children of the test suite element
  3. (Optional for Eclipse) : BenchmarkResult need a rename of WalltimeMilliseconds to walltime
  4. Append after the cases results a list of all messages
  5. Close the top level </TestCase>

File splitting

The purpose is to be able to save into one directory a XML file for each of the test case.

The XML header is an easy tag to detect the start of a new case.
Name of outputs files can just be incremented from one case to the next one ( result_1.xml, result_2.xml, etc.)

@e-j
Copy link
Owner Author

e-j commented May 7, 2015

In order to achieve the Consistent single file, a cout redirection can be useful. It can be a non-intrusive way of including each XML output provide by the Qt runner (for each case) into a unique normalized XML

Here is an example on how that can be provided :

#include <string>
#include <sstream>
#include <iostream>

std::streambuf* m_oldCoutStreamBuf;
std::ostringstream m_strCout;
/**
 * @brief Start redirect cout to a local buffer
 * @return TRUE if redirection succeed, FALSE else (redirection was already placed)
 */
bool AutoTestUtils::coutRedirectionStart(void){
    if( m_oldCoutStreamBuf ){
        return false;
    }
    m_oldCoutStreamBuf = std::cout.rdbuf(); // Backup cout
    std::cout.rdbuf( m_strCout.rdbuf() ); // Redirect cout to a local buffer
    return true;
}
/**
 * @brief Stop the cout redirection
 */
void AutoTestUtils::coutRedirectionStop(void){
    // Restore old cout
    std::cout.rdbuf( m_oldCoutStreamBuf );
    m_oldCoutStreamBuf = 0;
}
/**
 * @brief Clear the content of cout redirection buffer
 */
void AutoTestUtils::coutRedirectionClear(void){
    m_strCout.clear();
}
/**
 * @brief Get the content of cout redirection buffer as a QString
 * @return QString with the content of cout redirection buffer
 */
QString AutoTestUtils::coutRedirectionQString(void){
    return QString::fromStdString( coutRedirectionContent() );
}
/**
 * @brief Get the content of cout redirection buffer
 * @return The content of buffer as string
 */
std::string AutoTestUtils::coutRedirectionContent(void){
    return m_strCout.str();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant