【问题标题】:How to compose multiple unit test result in a single txt file如何在单个 txt 文件中编写多个单元测试结果
【发布时间】:2014-09-08 04:04:19
【问题描述】:

我正在使用 QTestLib 库和 QTest 来运行我的单元测试。我正在使用 Windows 7 并使用 Qt 4.8 当我使用以下方式运行测试时:

int main(int argc, char *argv[])
{
    // Test gui widgets - 2 Spinboxes and 1 Combobox
    QApplication a(argc, argv);
    TestSpinBox  testSpinBoxObj;
    TestComboBox testComboBoxObj;

    QTest::qExec(&testComboBoxObj, argc,argv);
    QTest::qExec(&testSpinBoxObj, argc,argv);

    return 0;
}

我在控制台中得到输出:

Starting D:\Projects\Qt Learning\TestGui (1)\TestGui\debug\TestGui.exe...
********* Start testing of TestComboBox *********
Config: Using QTest library 4.8.1, Qt 4.8.1
PASS   : TestComboBox::initTestCase()
PASS   : TestComboBox::testComboBoxStepUp()
PASS   : TestComboBox::testComboBoxStepDown()
PASS   : TestComboBox::cleanupTestCase()
Totals: 4 passed, 0 failed, 0 skipped
********* Finished testing of TestComboBox *********
********* Start testing of TestSpinBox *********
Config: Using QTest library 4.8.1, Qt 4.8.1
PASS   : TestSpinBox::initTestCase()
PASS   : TestSpinBox::testSpinBoxStepUp()
PASS   : TestSpinBox::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of TestSpinBox *********
D:\Projects\Qt Learning\TestGui (1)\TestGui\debug\TestGui.exe exited with code 0

如何在单个文本文件中获得相同的内容

【问题讨论】:

    标签: qt unit-testing qtestlib


    【解决方案1】:

    There is -o filename option to specify output file。对于每个测试对象,您可以将输出重定向到自己的文件,然后将它们连接在一起。

    QList<QObject *> objects;
    objects << new TestSpinBox << new TestComboBox;
    
    QString result;
    foreach (QObject *o, objects) {
        QTemporaryFile f;
        f.open();
        QStringList args = app.arguments();
        args << "-o" << f.fileName();
        QTest::qExec(o, args);
        result += "\r\n" + f.readAll();
    }
    qDeleteAll(objects);
    

    【讨论】:

      猜你喜欢
      • 2020-05-28
      • 2017-06-06
      • 2014-06-06
      • 2013-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-16
      相关资源
      最近更新 更多