Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members  

wxTest: A C++ Unit Test Framework

Version 0.1

Overview

wxTest is a test framework designed in the tradition of the xUnit family.  It's helpful for the development of automated test suites for C++ code.  wxTest consists of an interface specification between tests and test- runners, in the form of abstract virtual C++ classes.  This interface facilitates complete binary decoupling between the tests and the test modules.  Tests are packaged in separate modules (.DLLs, .shlbs, .sos, etc) and are completely decoupled from the test runner.

Despite the 'wx' prefix, wxTest can be used to test any C++ code, not just code that uses wxWindows.  The interface between tests and test runners is pure C++ and has no dependency to wxWindows.  wxTest includes two implementations of test runners: a GUI and a text-only version. 

 

Features

For the initial 1.0 release, only Win32, Macintosh (Carbon), and GTK/Linux are targeted  Not all of these features are currently implemented on all platforms:

Hierarchal Unit Tests.  Test cases are related hierarchally.  Tests are contained in a test suite.  Test suites may in turn be contained in other test suites.

Binary Decoupled Unit Tests:  Unit tests are packaged into separate dynamic libraries called "test- modules."  A test- module exports a single function "GetWXTest" which retrieves a pointer to the test suite implemented by the test module.  Test modules aren't linked to the test runner.  At runtime the test runner loads the test modules dynamically and calls the GetWXTest function to obtain a pointer to the modules test suites.

Unit-Test and Test-Runner Interfaces:  The interface between tests and test-runners is defined by pure abstract C++ classes.  This enables binary-decoupling in a cross platform manner.

Textual Test Runner:  Implements the "runner" side of the unit-test / test-runner interface.  It loads tests modules an executes unit tests, sending the output to stout.

GUI Test Runner:  Implements the "runner" side of the unit-test / test-runner interface.  It loads tests modules an executes unit tests and displays the test tree.  You can interactively browse through tests and execute them, or set , sending the output to stdout.  The GUI Test Runner has additional features, such as the ability to check textual output, and running test cases in multiple threads simultaneously to test for thread safety.

 

Building wxTest

You must first install and build wxWindows.  See http://www.wxwindows.org for the latest version and more information.

Win32: DevStudio 6

Configure your build environment for wxWindows' lib and include paths:  (From the menu, select Tool -- Options, and select the Directories tab.  Add the include and lib paths for wxWindows if they're not there already.).

In the folder wxTest/win32, open the workspace file wxTest.dsw.  Select from the menu Build -- Batch Build, make sure everything every target is checked, and click the 'Build' button.

Once it's built you can execute the wxTestRunnerGUI target to run the sample tests.

Macintosh:  CodeWarrior 6 / 7

Macintosh CodeWarrior support is not yet available.

Linux:

Linux support is not yet available.

 

Creating Unit Tests

Create a new test-module.  The easiest way to do this is to copy the entire contents of the 'sample' subdirectory to a new location, and to rename everything from 'Sample' to whatever you'd like to call it.  You'll also have to adjust the include and lib paths. I'm sorry there isn't a more automagical way of doing this, but there really isn't that much code there. 

Create a new class derived from wxTestCase.  ( Use SampleTests as a guide. )

Implement the Setup and TearDown functions to initialize or cleanup anything needed by your tests.  These are called before and after each call to the individual tests.

Implement one or more test functions.  The must have the signature   void TestFunctionName( wxITestRunner * pTestRunner, ThreadId threadId ).  This is where you put your actual test code.  The wxITestRunner pointer is the interface by which you test communicates with the test runner.  The threadId tells you which thread the thread in which the test function is being called.

Create a Suite method that returns a test-suite that can be used to call each of the test methods.  Use the wxTestCaller template class to populate a wxTestSuite object.  (See the sample for an example.)

Create the GetWXTest function using the WXTEST_EXPORT macro so it is exported from the shared library.  (See SampleTests.cpp for an example.)


ThunderCow Software (c) 2001 Marty Saxton, ThunderCow Software. Generated on Sat Nov 17 14:08:31 2001 for wxTest by Doxygen 1.2.11