Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Gui testing in Qt

I'm trying to stresstest an gui application and I'm not too sure how to do this. First I have an application where all the gui and helper functions are located. I also have two external libraries that I've made which this app uses. The libraries only do small things and I would like to unit test these parts when QtMock is up and working (currently its not compatible with qt 4.8 for some reason).

I would like to stress test the main application without having to change too much of the code. I had a look at QtTestLib and it seemed very basic and as if you had to integrate that code with the main code, which I dont want. I would really wanna keep the testing outside the app and was wondering how to do this? Not too sure if I should export my enitre gui app as a external lib that I could import into my test?

How do you usually do this to really stress test the entire thing. No idea how and where I should do the test code and I would appreciate any help!

like image 839
chikuba Avatar asked May 09 '12 22:05

chikuba


People also ask

What is Qt in testing?

Qt Test is a framework for unit testing Qt based applications and libraries. Qt Test provides all the functionality commonly found in unit testing frameworks as well as extensions for testing graphical user interfaces. Qt Test consists of about 6000 lines of code and 60 exported symbols.


1 Answers

In my experience, any test toolkit you use is either going to work itself into your code in subtle ways, or never get to the depth you need (or both).

It's possible to write custom test code and still keep the code clean for the app being tested. I did it on a large Windows C++ gui app that I needed to autotest. The basic idea is to create a new project, reference all the code from your base project, and write a new set of classes that derive from the base classes and that contain your testing code.

In my case, I created a new Visual Studio project, but you can do the same with a new Qt project. The base classes may have to be refactored to expose the functions to be tested, of course. The test classes call the base class functions as needed - you can create an entire test gui if you want.

As a very simple example, if this is your project...

class MyView : public QMainWindow {}
class MyController {}
class MyModel {}

...create a new project, pull in your base code, and add these:

class TestView       : public MyView {}
class TestController : public MyController {}
class TestModel      : public MyModel {}

In the end, after a little work, zero test code was in my base classes, and I was still able to tie in and fire off all kinds of repetitive autotests in a nice test gui.

I'm not saying this is an easy or trivial task. I'm just encouraging you that it can be done. :-)

EDIT: This is not a criticism of embedded unit testing, which is great if you can get it in place from the start of your project. But this was a large legacy app and it was a hard requirement that I didn't inject test code into the base code.

like image 60
moodboom Avatar answered Oct 16 '22 22:10

moodboom