views:

99

answers:

4

I am trying to build a test program in c++ to automate testing for a specific application. The testing will involve sending requests which have a field 'CommandType' and some other fields to a server

The commandType can be 'NEW', 'CHANGE' or 'DELETE' The tests can be

  1. Send a bunch of random requests with no pattern
  2. Send 100 'NEW' requests, then a huge amount of 'CHANGE' requests followed by 200 'DELETE' requests
  3. Send 'DELETE' requests followed by 'CHANGE' requests ... and so on

How can I design my software (what kind of modules or layers) so that adding any new type of test case is easy and modular?

EDIT: To be more specific, this test will be to only test one specific application that gets requests of the type described above and handles them. This will be a client application that will send the requests to the server.

A: 

I would separate out each individual test into it's own procedure or, if it requires code beyond a function or two, it's own source file. Then in my main routine I'd do something like:

void main()
{
    run_test_1();
    run_test_2();
    //...
    run_test_N();
}

Alternatively, I'd recommend leveraging the Boost Test Library and following their conventions.

fbrereto
A: 

I'm assuming you're not talking about creating unit tests.

IMHO, Your question is too vague to provide useful answers. Is this to test a specific application or are you trying to make something generic enough to test as many different applications as is possible? Where do these applications live? Are they client server apps, web apps, etc.?

If it's more than one application that you want your tool to test, you'll need an architecture that creates a protocol in between the testing tool and the applications such that you can convert the instructions your tool and consumers of your tool can understand, into instructions that the application being tested can understand. I've done similar things in the past but I've only ever had to worry about maybe 5 different "applications" so it was a pretty simple matter of summing up all the unique functionality of the apps and then creating an interfact that supports them all.

I wouldn't presume that NEW, CHANGE, and DELETE would be your only command types either. A lot of testing involves data cleanup, test reporting, etc. And applications all handle this their own special ways.

Atoms
+1  A: 

I would not create your own framework. There are many already written that follow a common pattern and can likely accomodate your needs elegantly.

The xUnit framework in all incarnations I have seen allows you to add new test cases without having to edit the code that runs the tests. For example, CppUnit provides a macro that when added to a test case will auto-register the test case with a global registry (through static initialization I assume). This allows you to add new test cases without cracking open and editing the thing that runs them.

And don't let the "unit" in xUnit and CppUnit make you think it is inappropriate. I've used the xUnit framework for all different kinds of testing.

SingleShot
A: 

use C++ unit testing framework , Read this for Detail and examples

sat