testqt5.cpp (730B)
1 // Example of Qt5 Unit test with QtTest library 2 // Federico Pellegrin, 2019 (fedepell) 3 4 #include "foo.h" 5 #include <QtTest/QtTest> 6 7 class TestQt5Test: public QObject { 8 Q_OBJECT 9 private: 10 Foo myFoo; 11 private slots: 12 void testGui(); 13 void testFunc(); 14 }; 15 16 // Test of the UI by simulating a button click and button label reading 17 void TestQt5Test::testGui() { 18 QCOMPARE(myFoo.m_button->text(), QString("Foo Button")); 19 QTest::mouseClick(myFoo.m_button, Qt::LeftButton,Qt::NoModifier, QPoint(5,5), 0); 20 QCOMPARE(myFoo.m_button->text(), QString("Button Foo")); 21 } 22 23 // Test of a normal function 24 void TestQt5Test::testFunc() { 25 QCOMPARE(myFoo.FortyTwo(), 44); // this fails! 42 != 44 26 } 27 28 QTEST_MAIN(TestQt5Test) 29 30 #include "testqt5.moc" 31