问题描述
我正在使用带有QtCreator 4.6.1的Qt Test进行单元测试。
我的简单测试类如下。
#include <QString>
#include <QtTest>
#include "../MyApplication/pen.h"
class MyApplicationTest : public QObject
{
Q_OBJECT
public:
MyApplicationtest();
private Q_SLOTS:
void testPenSetValue();
void testPenSetValue2();
};
MyApplicationTest::MyApplicationtest()
{
}
void MyApplicationTest::testPenSetValue()
{
Pen* p = new Pen();
p->setValue(5);
QCOMPARE( p->getValue(),5 );
}
void MyApplicationTest::testPenSetValue2()
{
Pen* p = new Pen();
p->setValue(5);
QCOMPARE( p->getValue(),5 );
}
QTEST_APPLESS_MAIN(MyApplicationTest)
#include "tst_myapplicationtest.moc"
但是似乎测试执行了两次。通过一次测试,我得到了如下结果。
Starting C:\Users\Lakshan\Documents\MyApplicationTest_Build\debug\tst_myapplicationtest.exe...
********* Start testing of MyApplicationTest *********
Config: Using QTest library 4.8.4,Qt 4.8.4
PASS : MyApplicationTest::initTestCase()
PASS : MyApplicationTest::testPenSetValue()
PASS : MyApplicationTest::testPenSetValue2()
PASS : MyApplicationTest::cleanupTestCase()
Totals: 4 passed,0 Failed,0 skipped
********* Finished testing of MyApplicationTest *********
********* Start testing of MyApplicationTest *********
Config: Using QTest library 4.8.4,0 skipped
********* Finished testing of MyApplicationTest *********
C:/Users/Lakshan/Documents/MyApplicationTest_Build/debug/tst_myapplicationtest.exe exited with code 0
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)