我正在使用 QTestLib 库和 QTest 来运行我的单元测试。我正在使用 Windows 7 并使用带有 MVSC 2010 编译器的 Qt 4.8。当我使用以下方法运行测试时:
QTest::qExec(TestDateDD/whateverTestClass);
我在控制台中得到输出:
********* 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 *********
但是,我的要求是在我的 GUI 中为每个测试槽显示此消息。我做了一些研究,发现qtestlog.cpp使用自己的 messageHandler 来管理测试输出并将结果显示为 PASS 或 FAIL 以及失败消息、行号等。有什么方法可以处理 QTest 的这个 messageHandler我的 GUI 应用程序?