ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 概述 ``` class TestQString: public QObject { Q_OBJECT private slots: void toUpper_data(); void toUpper(); }; ``` 2. 编写测试数据函数 ``` #include <QtTest> // 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<QString>("string"); QTest::addColumn<QString>("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" ``` 会执行两次结果