#ifndef SMART_H #define SMART_H #include <QObject> #include <QStringList> class Smart : public QObject { Q_OBJECT public: explicit Smart(QObject *parent, const QStringList& list); public slots: int max(int a, int b); int min(int a, int b); }; #endif // SMART_H
#include "smart.h" Smart::Smart(QObject *parent, const QStringList& list) : QObject(parent) { } int Smart::max(int a, int b) { if(a > b) return a; return b; } int Smart::min(int a, int b) { if(a < b) return a; return b; }
#ifndef TEST_SMART_H #define TEST_SMART_H #include <QObject> class Test_Smart : public QObject { Q_OBJECT public: explicit Test_Smart(QObject *parent = 0); private slots: // void max(); // int max(int, int) }; #endif // TEST_SMART_H
#include <QTest> #include "test_smart.h" #include "smart.h" Test_Smart::Test_Smart(QObject *parent) : QObject(parent) { } void Test_Smart::max() { Smart a; QCOMPARE(a.max(1, 0), 1); QCOMPARE(a.max(-1, 1), 1); QCOMPARE(a.max(4, 8), 8); QCOMPARE(a.max(0, 0), 0); QCOMPARE(a.max(1, 1), 1); QCOMPARE(a.max(-10,-5), -5); }
#include <QApplication> #include <QTest> #include <iostream> #include <cstdlib> #include <cstdio> #include "test_smart.h" using namespace std; int main(int argc, char *argv[]) { freopen("testing.log", "w", stdout); QApplication a(argc, argv); QTest::qExec(new Test_Smart, argc, argv); return 0; }
********* Start testing of Test_Smart ********* Config: Using QTest library 4.8.1, Qt 4.8.1 PASS : Test_Smart::initTestCase() PASS : Test_Smart::max() PASS : Test_Smart::cleanupTestCase() Totals: 3 passed, 0 failed, 0 skipped ********* Finished testing of Test_Smart *********
void Test_Smart::min_data() { QTest::addColumn<int>("first"); QTest::addColumn<int>("second"); QTest::addColumn<int>("result"); QTest::newRow("min_data_1") << 1 << 0 << 0; QTest::newRow("min_data_2") << -1 << 1 << -1; QTest::newRow("min_data_3") << 4 << 8 << 4; QTest::newRow("min_data_4") << 0 << 0 << 0; QTest::newRow("min_data_5") << 1 << 1 << 1; QTest::newRow("min_data_6") << -10 << -5 << -10; } void Test_Smart::min() { Smart a; QFETCH(int, first); QFETCH(int, second); QFETCH(int, result); QCOMPARE(a.min(first, second), result); }
********* Start testing of Test_Smart ********* Config: Using QTest library 4.8.1, Qt 4.8.1 PASS : Test_Smart::initTestCase() PASS : Test_Smart::max() PASS : Test_Smart::min() PASS : Test_Smart::cleanupTestCase() Totals: 4 passed, 0 failed, 0 skipped ********* Finished testing of Test_Smart *********
********* Start testing of Test_Smart ********* Config: Using QTest library 4.8.1, Qt 4.8.1 PASS : Test_Smart::initTestCase() PASS : Test_Smart::max() FAIL! : Test_Smart::min(data_1) Compared values are not the same Actual (a.min(first, second)): 1 Expected (result): 0 Loc: [test_smart.cpp(41)] FAIL! : Test_Smart::min(data_1) Compared values are not the same Actual (a.min(first, second)): 1 Expected (result): -1 Loc: [test_smart.cpp(41)] FAIL! : Test_Smart::min(data_1) Compared values are not the same Actual (a.min(first, second)): 8 Expected (result): 4 Loc: [test_smart.cpp(41)] FAIL! : Test_Smart::min(data_1) Compared values are not the same Actual (a.min(first, second)): -5 Expected (result): -10 Loc: [test_smart.cpp(41)] PASS : Test_Smart::cleanupTestCase() Totals: 3 passed, 4 failed, 0 skipped ********* Finished testing of Test_Smart *********
#ifndef TEST_QLINEEDIT_H #define TEST_QLINEEDIT_H #include <QObject> class Test_QLineEdit : public QObject { Q_OBJECT private slots: // void edit(); }; #endif // TEST_QLINEEDIT_H
#include <QtTest> #include <QtGui> #include "test_qlineedit.h" void Test_QLineEdit::edit() { QLineEdit a; QTest::keyClicks(&a, "abCDEf123-"); QCOMPARE(a.text(), QString("abCDEf123-")); QVERIFY(a.isModified()); }
#include <QApplication> #include <QTest> #include <iostream> #include <cstdlib> #include <cstdio> #include "test_smart.h" #include "test_qlineedit.h" using namespace std; int main(int argc, char *argv[]) { freopen("testing.log", "w", stdout); QApplication a(argc, argv); QTest::qExec(new Test_Smart, argc, argv); cout << endl; QTest::qExec(new Test_QLineEdit, argc, argv); return 0; }
********* Start testing of Test_Smart ********* Config: Using QTest library 4.8.1, Qt 4.8.1 PASS : Test_Smart::initTestCase() PASS : Test_Smart::max() PASS : Test_Smart::min() PASS : Test_Smart::cleanupTestCase() Totals: 4 passed, 0 failed, 0 skipped ********* Finished testing of Test_Smart ********* ********* Start testing of Test_QLineEdit ********* Config: Using QTest library 4.8.1, Qt 4.8.1 PASS : Test_QLineEdit::initTestCase() PASS : Test_QLineEdit::edit() PASS : Test_QLineEdit::cleanupTestCase() Totals: 3 passed, 0 failed, 0 skipped ********* Finished testing of Test_QLineEdit *********
Option | Explanation |
---|---|
-o filename | Displays test results in filename |
-silent | Limit messages to warnings and errors only. |
-v1 | Display information about the input and output of test methods |
-v2 | Complements the -v1 option with messages for the QCOMPARE and QVERIFY macros |
-vs | Display every sent signal and called slot |
-xml | Output all information in XML format |
-eventdelay ms | Make the test stop and wait for ms milliseconds. This option is useful for finding errors in GUI elements. |
Source: https://habr.com/ru/post/146449/
All Articles