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

Gilles Habran gilleshabran at gmail.com
Tue Apr 10 16:19:29 CEST 2012


Hi,

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 ?

Is there any documentation that explains that kind of thing (static link,
dynamic link, create library, ... and how to use that with unit test
compilation) ?

I don't know if what I say make sense or not so feel free to ask if it is
unclear. :)

Thanks again for your help.

On 10 April 2012 11:48, Samuel Gaist <samuel.gaist at edeltech.ch> wrote:

> The best answer i can give you is: it depends. I like to have a test
> project per class so i can run them manually while writing the related
> class and have them automatically called when doing automated test
> procedures.
>
> Have a look at the subdir template. Basically, you will end with several
> subdirs "project" :
> MyProject.pro -> subdir template
>
> apps/apps.pro -> subdir template
> apps/myapp/myapp.pro -> app template
>
> libs.pro -> subdir template
> libs/xxx/xxx.pro -> subdir template
> libs/xxx/src/src.pro -> lib template
> libs/xxx/test/test.pro -> subdir template
>
> It is one way of doing it, might not be the best, but works well for me.
>
> Hope its helps
> Samuel
>
> On 10 avr. 2012, at 11:05, Gilles Habran wrote:
>
> > Hi,
> >
> > I have to look for informations about how to separate my project to
> create a library then.
> >
> > Is it better to have a small project for each test class ? I have poor
> knowledge of unit testing of course but wouldn't it be more clear to have a
> big project containing all the unit test to start from time to time... but
> maybe it is different for TDD since you have to run the tests very often so
> you don't have to wait all the tests for the entire project to finish.
> >
> > I think I need a big tutorial. :)
> >
> > Thanks again.
> >
> > GH
> >
> > On 10 April 2012 10:43, Samuel Gaist <samuel.gaist at edeltech.ch> wrote:
> >
> > On 10 avr. 2012, at 10:29, Gilles Habran wrote:
> >
> > > Hi guys,
> > >
> > > I have a personal project and I would like to try to use Test Driven
> Development. For the moment, my only knowledge in Unit Tests come from
> several books, I never really use that concept in a project.
> > >
> > > Here is the arch of my project folder :
> > >
> > > xxx/xxx.pro
> > > xxx/src/*.cpp
> > > xxx/include/*.h
> > > xxx/obj/*.o
> > > xxx/bin/
> > >
> > > xxx/tests/yyy.pro
> > > xxx/tests/*.cpp & *.h
> > >
> > > So I have two projects, one for the main project and one for the
> tests, because I read that it's better that the tests do not mess with the
> project and I agree with that.
> > >
> > > For my test project, I plan to have a main.cpp that controls all the
> tests and my tests classes like this : testAAA.cpp+testAAA.h
> > >
> > > My problem is that I don't know how to "link" my project with unit
> tests to my main project.
> > > I read that I should either link my main project object files (.o)
> with my test project or have some .so to link to (my main project is not a
> library, it will have a GUI, DB access, XML, ... so how should I get that
> .so ?) or finally, add all the files mainProject.cpp and mainProject.h to
> the unit tests project to have access to them while compiling the project
> with unit tests.
> > >
> > > Can someone help me with documentation or good practice with unit
> testing with Qt (blog post, ...) ?
> > >
> > > I already have read the documentation for Qt Test Lib and I tested it
> (I included the .cpp in my test project files but it seemed really ugly)
> and it worked fine so I just need advises how to do it the proper way.
> > >
> > > Thanks a lot.
> > >
> > > Kind regards,
> > >
> > > GH
> > > _______________________________________________
> > > Interest mailing list
> > > Interest at qt-project.org
> > > http://lists.qt-project.org/mailman/listinfo/interest
> >
> > Hello,
> >
> > What I personally do for TDD with Qt is to develop all basic elements of
> my application in one or more libraries and then the application uses these
> elements so the hierarchy pretty much looks like this:
> >
> > MyProject/apps/xxx
> > MyProject/libs/xxx
> >
> > In the library I have:
> > xxx/xxx.pro
> > xxx/src/*.cpp/*.h
> > xxx/test/test.pro
> > xxx/test/test.pri
> > xxx/test/tst_class1
> > xxx/test/tst_class2
> >
> >
> > tst_class1/tst_class1.pro
> > tst_class1/tst_class1.cpp
> >
> > So each class has its own unit test.
> >
> > test.pri contains all the stuff that is needed to link against libxxx.so
> (dylib, dll etc...) and is included by all tst_xxx.pro
> >
> > Hope this helps
> > Samuel
> >
> > _______________________________________________
> > Interest mailing list
> > Interest at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120410/d10d98ab/attachment.html>


More information about the Interest mailing list