Please nominate your Qt Champions for 2021! https://forum.qt.io/topic/132134/looking-for-the-2021-qt-champions
Testing Database with QTest
I would like to write some QTest for database class, like connecting to database, insert tables , data.... I am beginner in this field and don't have a clue how should I start with it. I read some articles which mostly were about testing GUI. But they did not help me so far. I appreciate someone who could give me further information.
Suths last edited by
I would recomend you have a look at -> voidrealms.com
Suths thanks for the suggestion.
But I still could not find QTest example. I know how to connect to database and get the query from but I don't know how am I supposed to write some QTest(UnitTest) for it. :(
MuhamedAuda last edited by
Did u read chapter 16: Unit Testing in the Book: Foundations of Qt Development ?
sptrakesh last edited by
Not related to databases, but the same type of concepts apply to testing as with anything else. Take a look at the tests under
Thank you MuhamedAuda for introducing the Book. I have read the UnitTest chapter. The first test I wrote is as following:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setDatabaseName("test"); db.setHostName("localhost"); db.setUserName("************"); db.setPassword("************"); QVERIFY(db.isValid()); QCOMPARE(db.isOpen(), true);
in the normal case my connection will be established but in this case I got fail by QCOMPARE. Could anyone tell me where my error is?
Question: what are the alternatives for testing the methods of another subproject in my test project?
Ok I got my error.
I have to write @QCOMPARE(db.open(), true)@
But I still am looking forward to any suggestions that may help me to test the methoes of other subprojects in my test projects.