Gui based unit test framework in cpp

Jul 27, 2011 at 12:05am
Hi all,

Does any one know of a gui interface for unit testing C++ code i.e a framework which will list all the classes and methods(like an IDE) and lets us invoke them on click of a button after input parameters are given through the gui.I searched online and the forums, but could not find any.

Any pointers appreciated,

Jul 27, 2011 at 12:26am
Visual Studio IDE is the obvious choice for Windows, although It is Microsoft, for learning how to make a GUI It's easy. Just wouldn't consider it for "serious" projects and cross-platform applications.

Codeblocks with wxForge.

There is also one for Bloodshed C++.
Jul 27, 2011 at 12:41am
Thank you for replying Turbine!!

Is wxForge a plugin for code blocks? Also I do not want an IDE, I want a gui driven test framework. I mentioned IDE to indicate that it should list the methods like an IDE does. Please pardon and correct me if I missed something in your reply.



I would want it to run on linux as that is my development environment.
Jul 27, 2011 at 8:33pm
Any more ideas?? I am thinking wrting a ui interface to methods using qt, please do suggest if you have better ideas
Jul 27, 2011 at 10:09pm
I find your question a bit unclear: do you mean a tool which parses your C++ source, lists all the classes, methods, etc, and then generates code to call all the methods? (on the click of a button).
Jul 28, 2011 at 6:49pm
Kind of :) May be its too much to ask for. It should give me hooks to call the methods like Junit and associate the ui button clicks to invoke the test methods. Right now I am thinking of designing UI using QT and write code to invoke my c++ methods. Any ideas???
Jul 28, 2011 at 8:09pm
There is a C++ port of JUnit -- CppUnit

http://sourceforge.net/apps/mediawiki/cppunit/index.php?title=Main_Page

And there is already a Qt-based GUI to run CppUnit tests

http://qxrunner.systest.ch/qxcppunit/

Note that this app has a LGPL license.

Andy
Last edited on Jul 28, 2011 at 8:09pm
Jul 31, 2011 at 12:57am
Thank you Andy, I checked out qxcpp, but it seemed just automated running of all the methods. The main requirement is to have a gui to take the input the paramters to a method. The running of tests will not be automated, its a like a user manually testing a method through ui.
Aug 29, 2011 at 7:39pm
Hi all,

Ok, now I went ahead and created a qt based gui to test our api. The user sees a list of api methods, then he goes and clicks on a method he wants to test. A input page appears to take the input parameters, when user clicks submit,the click handler calls the api method and displays the output of the method. If it is a getMethod, displays what the get method retruned, if its a object, the I have a output page will display contents of the object.

Now the problem is this doesnot scale. Whenever api changes I have to change the input and output pages to reflect the change. Instead I want a c++ code generator that can create qt pages for me.
<?xml version="1.0"?>
<APIMethods>
<APIMethod name="multiply">
<input>
<label id="ilNum1" text="Num1: "/>
<Lineedit id="itNum1"/>
<label id="ilNum2" text="Num2: "/>
<Lineedit id="itNum2"/>
<button id="ibSubmit" text="Submit"/>
</input>
<output>
<lable id="olResult" text="Result: "/>
<Lineedit id="otResult"/>
<button id="obClose" text="Close"/>
</output>
<error>
<label id="olErrormessage"/>
</error>
</APIMethod>
</APIMethods>


The qt code looks like this:
The header file looks like this:

class Multiply : public QWidget
{
Q_OBJECT

public:
explicit Multiply(QWidget *parent = 0);
~Multiply();

public slots:
submitButtonHandler();

private:

QGroupBox inGroupBox;
QGroupBox outGroupBox;
QGroupBox outEGroupBox;

QStackedWidget outputStack;

QLabel ilNum1;
QLineEdit itNum1;
QLabel ilNum2;
QLineEdit itNum2;
QPushButton ibsubmit;

QLabel olResult;
QLabel otResult;
QPushButton obClose;

QLabel olErrorMessage;

QFormLayout inputLayout;
QFormLayout outputSLayout;
QHBoxLayout outputELayout;
QHBoxLayout pageLayout;


};

The cpp file looks like below:
#include "Multiply.h"
#include "QGroupBox"

Multiply::Multiply(QWidget *parent) :
QWidget(parent)

{
ilNum1.setText("Num1: ");
ilNum2.setText("Num2: ");
ibSubmit.setText("Submit");

olResult.setText("Result: ");
olclose.setText("Close");

inputLayout.addRow(&ilNum1,&itNum1);
inputLayout.addRow(&ilNum2,&itNum2);
inputLayout.addRow(&ibSubmit);

inGroupBox.setLayout(&inputLayout);

outputSLayout.addRow(&olResult,&otResult);
outputSLayout.addRow(&obClose);
outGroupBox.setLayout(&outputSLayout);

outputELayout.addWidget(&olErrorMessage);
outEGroupBox.setLayout(&outputELayout);

outputStack.addWidget(&outGroupBox);
outputStack.addWidget(&outEGroupBox);
//outputStack.hide();

pageLayout.addWidget(&inGroupBox);
pageLayout.addWidget(&outputStack);

setLayout(&pageLayout);


}
Multiply::submitButtonHandler(){


}
Is there a way I can use some tool to generate this code in header and cpp files given the above xml. I will still write the submit button handler code, but the task of layout and creating labels should be automated. Anyone know which tool could be used to do this job?

Thanks in advance!!!
Last edited on Aug 29, 2011 at 7:43pm
Aug 29, 2011 at 9:51pm
Looks like a perl script to write the .h and .cpp files is the way to go. any suggestions??
Aug 30, 2011 at 11:56am
Sounds like a good possibility. I have done the same sort of thing using Python, but to generate console-based tests.

The header side of things is definitely possible. But I did have to provide code for some the test cases in the cpp file manually.

You might want to look into defining a test base class which sits between QWidget and the generated test class, to cut down on the amount of generated code. It might make sense to hide the Qt specifics from the test code, too.
Last edited on Aug 30, 2011 at 11:57am
Aug 30, 2011 at 5:48pm
Thanks Andy..Wanted to know if there was a tool. Perl is good enough for me..thanks!!
Aug 30, 2011 at 8:12pm
I suppose that you want something for free? If you or your company is willing to pay, there are tools developed by parasoft and vector software that provide automated unit testing for C++.
Topic archived. No new replies allowed.