3

我正在使用 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

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

4

1 回答 1

1

有 -o 文件名选项来指定输出文件。对于每个测试对象,您可以将输出重定向到自己的文件,然后将它们连接在一起。

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);
于 2014-07-17T11:54:09.650 回答