数据驱动测试程序\’
最后更新于:2022-04-02 02:10:07
[TOC]
## 概述
```
class TestQString: public QObject
{
Q_OBJECT
private slots:
void toUpper_data();
void toUpper();
};
```
2. 编写测试数据函数
```
#include
// add necessary includes here
class TestQString : public QObject
{
Q_OBJECT
public:
TestQString();
~TestQString();
private slots:
void toUpper_data();
void toUpper();
};
TestQString::TestQString()
{
}
TestQString::~TestQString()
{
}
void TestQString::toUpper_data()
{
QTest::addColumn("string");
QTest::addColumn("result");
QTest::newRow("all lower") << "hello" << "HELLO";
QTest::newRow("mixed") << "Hello" << "HELLO";
QTest::newRow("all upper") << "HELLO" << "HELLO";
}
void TestQString::toUpper()
{
QFETCH(QString, string);
QFETCH(QString, result);
QCOMPARE(string.toUpper(), result);
}
QTEST_APPLESS_MAIN(TestQString)
#include "tst_word1.moc"
```
会执行两次结果
';