Wednesday, April 28, 2010

Sample Multiple Unit Test Project

Long time no post...

Anyway, someone asked me if I could upload a working test project that shows my AutoTest header in use, so click here to download test.zip which includes two sample test classes and a main.cpp that shows two ways to start the tests running.

Open the test.pro file using Qt Creator, build it and let it rip and you should see output that looks something like this:

********* Start testing of Test2 *********
Config: Using QTest library 4.6.2, Qt 4.6.2
PASS : Test2::initTestCase()
PASS : Test2::test1()
FAIL! : Test2::test2() Compared strings are not the same
Actual ("Hello"): Hello
Expected ("World!"): World!
test2.cpp(14) : failure location
PASS : Test2::cleanupTestCase()
Totals: 3 passed, 1 failed, 0 skipped
********* Finished testing of Test2 *********
********* Start testing of Test1 *********
Config: Using QTest library 4.6.2, Qt 4.6.2
PASS : Test1::initTestCase()
PASS : Test1::test1()
FAIL! : Test1::test2() '1 == 0' returned FALSE. ()
test1.cpp(14) : failure location
PASS : Test1::cleanupTestCase()
Totals: 3 passed, 1 failed, 0 skipped
********* Finished testing of Test1 *********


I hope you find this useful - it has certainly made my life easier when using QTestLib.