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.
Wednesday, April 28, 2010
Subscribe to:
Post Comments (Atom)
Thanks ... this was helpful.
ReplyDeleteThank you! Very helpful in understanding the concept of unit tests
ReplyDeletepretty helpful, thanks a lot!
ReplyDeleteReally Awesome!!
ReplyDeleteRob, this is great, thanks.
ReplyDeleteHowever, could you clarify how you set up your folders and paths when testing a project?
Qt Creator default is for the main project and test project to live in separate folders (and for their source and build to also remain separate).
Including the main project's headers in the test project is simple (just add to the INCLUDEPATH in the .pro file), but I'm so far unable to get the test project's linker to find the main project's .o files and the symbols therein.
Can you help?
Regards
Jay.
This comment has been removed by the author.
ReplyDeleteI do not understand the working of AutoTest.h file. code is complicated. Can anyone please explain.
ReplyDeleteRob, it is great.
ReplyDeleteCould I translate this into Chinese and put it on my blog? For blogspot.com is blocked by the Chinese government.
Of cause I would put the source link there.
Feel free to take the article and do what you want with it.
ReplyDeleteHi Rob,
ReplyDeleteWhy did you skip line at the end of test file
#include "some_file.moc"?
Is it no longer necessary when we have yours implementation?
Great stuff, but I am afraid that ./testBin -function returns only the test functions from the last added class file to the .pro in HEADERS.
ReplyDeleteThanks!
ReplyDeleteGreat job Rob..Many Thanks :)
ReplyDeleteThank you! This is the very first article helping me with Qt Testing. It costed me hours of googling to find it
ReplyDeleteGlad to be of help.
ReplyDeleteThanks for sharing! Just what I needed, clean and simple!
ReplyDeleteRob, what license do you provide your code with?
ReplyDeleteWould it be possible to use it in the commercial project?
Use it however you like, just don't take credit for it. Commercial projects are fine.
DeleteThank you. Really useful!
DeleteIt would be nice if you would add a license/author comment to the top of the file.
Very, very helpful! Thanks alot!
ReplyDelete"Sorry, you can't view or download this file at this time. Too many users have viewed or downloaded this file recently. [...]" - Would be nice to embed the code and / or provide a different download possibility. Only managed to download them via the diversion using the "Zip Extractor" App on Google Drive...
ReplyDeleteVery bad sample
ReplyDeleteThis is great, If you ever are in Amsterdam I owe you a beer
ReplyDeleteNice article Rob,
ReplyDeleteIt would be really helpfull if you tell us how to get TestRun report in xml format. For now we get only one "test1" result in xml but we want both test cases "test1" and "test2 "in single xml file.
Thanks
This is great.
ReplyDeleteBy the way, you can get Jenkins-Xunit-plugin compatible xml output by running this with
./UnitTests -xml > result.xml
Then split the result.xml at the <?xml version tag using:
csplit -zs -f qunittest -b %02d.xml result.xml '/<\?xml/' '{*}'
Don't forget to select QTestlib as the origin of the test results.
Hello, I am unable to access the source code on the link given. Seems it has been removed and this post is very old. Is there any way I can access that code?
ReplyDelete^^^^^ Please please!! :)
Deleteplease++
ReplyDeleteplease++
ReplyDelete