[Interest] How to use unit testing with Qt framework properly
Samuel Gaist
samuel.gaist at edeltech.ch
Wed Apr 11 13:23:02 CEST 2012
Hi,
Using the subdir template, you would only have one project opened in Creator, all the other "subproject" are contained in it. So only one build to manage and you can select which test you'd like to run in the run settings panel. And if you want to run them all every time you build, add a buildstep with "check" as Make arguments.
Samuel
On 10 avr. 2012, at 22:31, Gilles Habran wrote:
> Hi again,
>
> I created a dummy project to test some things. You can find the project here : https://bitbucket.org/hiveNzin0/qtunittest
>
> I would like to know if it is "clean" to do like I did in the main.cpp in tests/unitTests ? That's the result I wanted.
> I tried to create on project for each class but I don't think I would like to have too many open projects in Qt Creator for instance (I still need experience in Unit Testing) and I still don't know how to setup this.
>
> I still have problems to link correctly my main project and my test project as you can see in the unitTests.pro, I'm still looking for informations about that.
>
> Any advise appreciated. :)
>
> Thanks.
>
> Regards,
>
> GH
>
> On 10 April 2012 16:19, Gilles Habran <gilleshabran at gmail.com> wrote:
> 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
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
More information about the Interest
mailing list