I want use QTest Macro QCOMPARE in my code,but I receive errors.
QTestString.h
#ifndef QTESTSTRING_H
#define QTESTSTRING_H
#include <QtCore/QString>
#include <QtTest/QtTest>
class TestqstringTest : public QObject
{
Q_OBJECT
public:
TestqstringTest();
private slots:
void testCase1();
};
#endif // QTESTSTRING_H
QTestString.cpp
#include "QTestString.h"
TestqstringTest::TestqstringTest()
{
testCase1();
}
void TestqstringTest::testCase1()
{
QString str = "Hello";
QCOMPARE(str.toUpper(),(QString)"hELLO");
}
main.cpp
#include "QTestString.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
TestqstringTest *test = new TestqstringTest();
return a.exec();
}
However, I receive the following errors:
ASSERT: "QTest::testLogger" in file qtestlog.cpp, line 266 The program has unexpectedly finished.
I found the answer,you must use int QTest::qExec ( QObject * testObject, int argc = 0, char ** argv = 0 )
to excute it ,then the testlog output correctly.