[Closed]How to get the information from QTestLib/QTest on test failure.



  • Hi,
    I am using QTestLib Library and QTest for running my unit tests. I am working on windows 7 and using Qt 4.8 |MVSC 2010 compiler.
    When i run my test using
    QTest::qExec(TestDateDD/whateverTestClass);

    i get the output in the console :
    @
    ********* Start testing of TestDateDD *********
    Config: Using QTest library 4.8.0, Qt 4.8.0
    PASS : TestDateDD::initTestCase()
    PASS : TestDateDD::testValidity()
    FAIL! : TestDateDD::testMonth(2012/7/10) Compared values are not the same
    Actual (date.longMonthName(date.month())): July
    Expected (monthname): June
    ..\UnitTestingPlugiin\TestDateDD.cpp(38) : failure location
    PASS : TestDateDD::cleanupTestCase()
    Totals: 3 passed, 1 failed, 0 skipped
    ********* Finished testing of TestDateDD *********@

    My requirement is to set some parameter's/message in my Application/Ui if the test has failed. How can i seperate or get the information if the test fails.

    @if(test_failed)
    {
    qdebug()<<"UnSuccessful";
    }
    else
    {
    qdebug()<<"Successful";
    }@



  • okay I got how to check if the test has failed using an integer and checking its value like :

    @int result=0;

    result = QTest::qExec(TestDateDD)

    if(result==0)
    {
    QIcon icon(":/Files/Image/tick.png");
    colItem->setIcon(icon);
    }
    else
    {
    QIcon icon(":/Files/Image/error.png");
    colItem->setIcon(icon);
    }@

    but now my requirement is to get the name and details of the test slot that failed and the failure location like

    @
    FAIL! : TestDateDD::testMonth(2012/7/10) Compared values are not the same
    Actual (date.longMonthName(date.month())): July
    Expected (monthname): June
    ..\UnitTestingPlugiin\TestDateDD.cpp(38) : failure location@



  • I did some initial search and found "qtestlog.cpp":http://qt.gitorious.org/qt/qt/blobs/HEAD/src/testlib/qtestlog.cpp that uses a messageHandler. Is the any way to access this messageHandler while running out QTest::qExec() function. I also found "this":https://bugreports.qt-project.org/browse/QTBUG-525?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.