[Interest] How to use unit testing with Qt framework properly
Samuel Gaist
samuel.gaist at edeltech.ch
Tue Apr 10 11:48:43 CEST 2012
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
More information about the Interest
mailing list