[Interest] How to use unit testing with Qt framework properly

Bo Thorsen bo at fioniasoftware.dk
Thu Aug 2 11:41:33 CEST 2012

Hi Gilles,

This mail was sent quite a lot of months ago, but I hope you'll allow me 
to get back to it.

Den 10-04-2012 16:19, Gilles Habran skrev:
> thanks again for all the informations. I think I will create another
> test project to experiment a lot with the Qt Test Lib and see what I can
> do and not do.
> I didn't understand how you call them automatically when you do
> automated test proc. You have one main for each file (test class), do
> you create another main somewhere that call all the tests ?
> What I would like to achieve is
> 1) run small unit tests for a class only for example
> 2) run all the available tests in folder tests for example
> I suppose I will have to do it your way.
> Is it really a good way to do when you separate the app (I suppose the
> main) and create a library with all the other class/... ? I am trying to
> see the pros and cons of this. I checked with some KDE projects and I
> only saw KTorrent with the separation. I will try to find projects that
> use Qt test lib or KDE test lib (if such thing exists) and see how they
> do it.
> How should I do to link my main project with my tests projects if I
> don't want to create a library for my main project ?

I actually have a small but complete example of how you can do this with 
Qt: http://fioniasoftware.dk/fseditor.html.

It's a small text editor, but the software itself is irrelevant. What's 
important here is all the things it puts together. Among other things, 
it has a unit test suite that runs as part of the build process. You can 
take a look at this and see how I choose to do it.

I have had this up with a cmake based build for a long time. But I just 
published the qmake based version today (which is why I send this mail 
now). I'll post a blog entry on qmake versus cmake within a couple of 
days on the FS blog.

I hope you or others find this useful.

Bo Thorsen,
Fionia Software.


Expert Qt and C++ developer for hire
Contact me if you need expert Qt help

More information about the Interest mailing list