2016-09-19 82 views
2

在Qt單元測試中,程序如何檢索正在運行的測試的名稱?QTest獲得測試名稱

代碼看起來是這樣的:

#include <QtTest> 
class MyTest : public QObject 
{ 
    Q_OBJECT 

private Q_SLOTS: 
    void initTestCase() 
    { 
    } 

    void testCase1() 
    { 
    } 

    void cleanupTestCase() 
    { 
     // Want to print "finished testCase1" here 
    } 
}; 

QTEST_APPLESS_MAIN(MyTest) 

例如它能找出觸發測試的信號/插槽的名稱嗎?

回答

1

QTest::currentTestFunction()應作爲一個const char *

返回名稱目前的測試功能順便說一句,也許你希望把它放在一個cleanup函數中,而不是cleanupTestCase?看來cleanup是在每次測試後調用的,而cleanupTestCase只有在所有測試完成後纔會調用。