Testing Database with QTest
-
wrote on 7 Nov 2012, 14:31 last edited by
Hello,
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.
-
wrote on 7 Nov 2012, 14:37 last edited by
I would recomend you have a look at -> voidrealms.com
-
wrote on 7 Nov 2012, 14:47 last edited by
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. :( -
wrote on 7 Nov 2012, 15:12 last edited by
Did u read chapter 16: Unit Testing in the Book: Foundations of Qt Development ?
-
wrote on 7 Nov 2012, 15:46 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
http://kenai.com/projects/mongoviewer/sources/svn/show/bson/trunk/src/test?rev=140
-
wrote on 8 Nov 2012, 14:45 last edited by
Thank you MuhamedAuda for introducing the Book. I have read the UnitTest chapter. The first test I wrote is as following:
@
void TestDBMethods::testConnection(){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?
-
wrote on 8 Nov 2012, 15:11 last edited by
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.
1/7