|
Packit |
8c9aa0 |
/**
|
|
Packit |
8c9aa0 |
\mainpage
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
\section _history History
|
|
Packit |
8c9aa0 |
The first port of JUnit to C++ was done
|
|
Packit |
8c9aa0 |
by Michael Feathers. His versions
|
|
Packit |
8c9aa0 |
can be found on the
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
XProgramming software page. They are os-specific,
|
|
Packit |
8c9aa0 |
so Jerome Lacoste provided a port to Unix/Solaris.
|
|
Packit |
8c9aa0 |
His version can be found on the same page.
|
|
Packit |
8c9aa0 |
The %CppUnit project has combined and built on this work.
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
\section _usage Usage
|
|
Packit |
8c9aa0 |
Take a look into the \ref cppunit_cookbook.
|
|
Packit |
8c9aa0 |
It gives a quick start into using this
|
|
Packit |
8c9aa0 |
testing framework. Modules give
|
|
Packit |
8c9aa0 |
you a organized view of %CppUnit classes.
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
(Notes to newbies, you may want to check out \ref money_example,
|
|
Packit |
8c9aa0 |
a work in progress, but the project is provided with %CppUnit).
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
For a discussion on %CppUnit, check
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
the WikiWiki Pages on CppUnit. There you can also
|
|
Packit |
8c9aa0 |
find the original versions and various ports to other
|
|
Packit |
8c9aa0 |
OSses and languages.
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
\section _license License
|
|
Packit |
8c9aa0 |
This library is released under
|
|
Packit |
8c9aa0 |
the GNU
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
Lesser General Public License.
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
\author Eric Sommerlade (sommerlade@gmx.net)
|
|
Packit |
8c9aa0 |
\author Michael Feathers (mfeathers@objectmentor.com)
|
|
Packit |
8c9aa0 |
\author Jerome Lacoste (lacostej@altern.org)
|
|
Packit |
8c9aa0 |
\author Baptiste Lepilleur <blep@users.sourceforge.net>
|
|
Packit |
8c9aa0 |
\author Bastiaan Bakker <bastiaan.bakker@lifeline.nl>
|
|
Packit |
8c9aa0 |
\author Steve Robbins <smr99@sourceforge.net>
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \defgroup WritingTestFixture Writing test fixture
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \defgroup Assertions Making assertions
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \defgroup CreatingTestSuite Creating TestSuite
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \defgroup ExecutingTest Executing test
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \defgroup TrackingTestExecution Tracking test execution
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \defgroup WritingTestResult Writing test result
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \defgroup BrowsingCollectedTestResult Browsing collected test result
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \defgroup CreatingNewAssertions Creating custom assertions
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \defgroup WritingTestPlugIn Writing Test Plug-in
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* Creating a test plug-in is really simple:
|
|
Packit |
8c9aa0 |
* - make your project a dynamic library (with VC++, choose Win32 Dynamic Library in
|
|
Packit |
8c9aa0 |
* the project wizard), and link against the dynamic library version of %CppUnit
|
|
Packit |
8c9aa0 |
* (cppunit*_dll.lib for VC++).
|
|
Packit |
8c9aa0 |
* - in a cpp file, include TestPlugIn.h, and use the macro CPPUNIT_PLUGIN_IMPLEMENT()
|
|
Packit |
8c9aa0 |
* to declare the test plug-in.
|
|
Packit |
8c9aa0 |
* - That's it, you're done! All the tests registered using the TestFactoryRegistry,
|
|
Packit |
8c9aa0 |
* CPPUNIT_TEST_SUITE_NAMED_REGISTRATION, or CPPUNIT_TEST_SUITE_REGISTRATION will
|
|
Packit |
8c9aa0 |
* be visible to other plug-in and to the DllPlugInRunner.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* Example:
|
|
Packit |
8c9aa0 |
* \code
|
|
Packit |
8c9aa0 |
* #include <cppunit/include/plugin/TestPlugIn.h>
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* CPPUNIT_PLUGIN_IMPLEMENT();
|
|
Packit |
8c9aa0 |
* \endcode
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* The interface CppUnitTestPlugIn is automatically implemented by the previous
|
|
Packit |
8c9aa0 |
* macro. You can define your own implementation.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* To provide your custom implementation of the plug-in interface, you must:
|
|
Packit |
8c9aa0 |
* - create a class that implements the CppUnitTestPlugIn interface
|
|
Packit |
8c9aa0 |
* - use CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL() with your class to export
|
|
Packit |
8c9aa0 |
* the plug-in interface
|
|
Packit |
8c9aa0 |
* - implements the 'main' function with CPPUNIT_PLUGIN_IMPLEMENT_MAIN().
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* Some of the reason you may want to do this:
|
|
Packit |
8c9aa0 |
* - You do not use the TestFactoryRegistry to register your test.
|
|
Packit |
8c9aa0 |
* - You want to create a custom listener to use with DllPlugInRunner.
|
|
Packit |
8c9aa0 |
* - You want to do initialize some globale resources before running the test
|
|
Packit |
8c9aa0 |
* (setting up COM for example).
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* See CppUnitTestPlugIn for further detail on how to do this.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* Creating your own test plug-in with VC++:
|
|
Packit |
8c9aa0 |
* - Create a new "Win32 Dynamic Library" project, choose the empty template
|
|
Packit |
8c9aa0 |
* - For the Debug Configuration, add cppunitd_dll.lib to
|
|
Packit |
8c9aa0 |
* 'Project Settings/Link/Object/Libariries modules', and for the Release
|
|
Packit |
8c9aa0 |
* Configuration, add cppunit_dll.lib.
|
|
Packit |
8c9aa0 |
* - For All Configuration, in 'C++/Preprocessor/Preprocessors definitions',
|
|
Packit |
8c9aa0 |
* add the symbol 'CPPUNIT_DLL' at the end of the line (it means that
|
|
Packit |
8c9aa0 |
* you are linking against cppunit dll).
|
|
Packit |
8c9aa0 |
* - Create a 'main' file that contains:
|
|
Packit |
8c9aa0 |
\verbatim
|
|
Packit |
8c9aa0 |
#include <cppunit/plugin/TestPlugIn.h>
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
CPPUNIT_PLUGIN_IMPLEMENT();\endverbatim
|
|
Packit |
8c9aa0 |
* - Add your tests
|
|
Packit |
8c9aa0 |
* - You're done !
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* See examples/simple/simple_plugin.dsp for an example.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* Notes to VC++ users:
|
|
Packit |
8c9aa0 |
* - you can run a post-build check on the plug-in. Add the following line to your
|
|
Packit |
8c9aa0 |
* post-build tab: "DllPlugInTesterd_dll.exe $(TargetPath)". DllPlugInTesterd_dll.exe
|
|
Packit |
8c9aa0 |
* need to be some place were it can be found (path, ...), or you need to
|
|
Packit |
8c9aa0 |
* indicate the correct path.
|
|
Packit |
8c9aa0 |
* $(TargetPath) is the filename of your plug-in.
|
|
Packit |
8c9aa0 |
* - you can debug your DLL, set the executable for debug session to the plug-in
|
|
Packit |
8c9aa0 |
* runner, and the name of the DLL in the program arguments ($(xxx) won't work
|
|
Packit |
8c9aa0 |
* this time).
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* How does it works ?
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* When %CppUnit is linked as a DLL, the singleton used for the TestFactoryRegistry
|
|
Packit |
8c9aa0 |
* is the same for the plug-in runner (also linked against %CppUnit DLL). This means
|
|
Packit |
8c9aa0 |
* that the tests registered with the macros (at static initialization) are
|
|
Packit |
8c9aa0 |
* registered in the same registry. As soon as a DLL is loaded by the PlugInManager,
|
|
Packit |
8c9aa0 |
* the DLL static variable are constructed and the test registered to the
|
|
Packit |
8c9aa0 |
* TestFactoryRegistry.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* After loading the DLL, the PlugInManager look-up a specific function exported by
|
|
Packit |
8c9aa0 |
* the DLL. That function returns a pointer on the plug-in interface, which is later
|
|
Packit |
8c9aa0 |
* used by the PlugInManager.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* \see CreatingTestSuite.
|
|
Packit |
8c9aa0 |
*/
|