views:

40

answers:

1

Hi,

If I were to create a unit test for class implementation using QTestlib ( trying to figure it out) how would I do it. (I know unit testing for the simple class below can be done other simple way I trying to understand QTestlib framework and whether its really what I want)

Consider a simple class ( just to make things really clear )

//Add.h

class Add {
           public:
           int add (int a , int b);
};


//Add.cpp 

int Add::add(int a, int b)
{
int c=0;
c=a+b;
return c;
}

How should I use QTestlib to test this class? Some info would be great.

If this isnt the right way. Let me know. Also some info on automated testing would be nice.

A: 

Take a look at http://doc.trolltech.com/4.6/qtestlib-manual.html#creating-a-test, it explains step-by-step how to create a test using QTestLib in a very accessible way.

Greg S
I did go through the site earlier my doubt comes from the line:"QTestLib is designed to ease the writing of unit tests for Qt based applications and libraries"Since the above class is just plain c++ and not QT..does it mean that I cant use it?
Sii
@MrProg: your class doesn't have to be derived from `QObject` to be used with `QTestLib`, so you can definitely use it, even if the rest of your application isn't based on Qt; nevertheless, in that case, I'd seriouly considering using another testing framework, using Qt for just that purpose seems like overkill.
Greg S