示例:
// main.cpp
#include <QTest>
#include "TestQString.h"
QTEST_MAIN(TestQString);
// TestQString.h
#ifndef TESTQSTRING_H
#define TESTQSTRING_H
#include <QObject>
class TestQString : public QObject
{
Q_OBJECT
public:
TestQString();
~TestQString();
private slots:
void toLower();
void toLower_data();
void toUpper();
void toTestUI();
void toTestUI_data();
};
#endif // TESTQSTRING_H
// TestQString.cpp
#include "TestQString.h"
#include <QtTest/QtTest>
#include <QtWidgets/QtWidgets>
TestQString::TestQString() : QObject()
{
}
TestQString::~TestQString()
{
}
void TestQString::toUpper()
{
QString str = "test";
QVERIFY(str.toUpper() == "TEST");
QVERIFY(str.toUpper() == "test");
QVERIFY(str.toUpper() == "Tes