CppUnit
CppUnit | |
---|---|
Basic data
|
|
Current version | 1.15.1 (December 25, 2019) |
operating system | Cross-platform |
programming language | C ++ |
category | Unit test |
License | GNU Lesser General Public License |
German speaking | No |
freedesktop.org/wiki/Software/cppunit |
CppUnit is a unit test - Framework for the programming language C ++ . It is based on the Java tool JUnit .
CppUnit tests program units (mostly classes). To create a new test, a new class is created which is extended with CppUnit macros. The methods of the class are registered as tests. Methods of other classes can now be tested within the methods. This usually involves testing whether a specific input produces correct output. The results of the tests can be displayed machine-readable in XML , as text output or with the supplied GUI- based programs.
Features
CppUnit has the following properties:
- XML output with elements for additional information
- Compiler-like text output for integration into IDEs
- Macros for the easy creation of test suites
- Support of hierarchical tests (tests that are composed of simpler tests)
- Test registration for faster code generation
- Test plug-in for faster compile / test cycles (self-test capable dynamic library)
- Protection mechanism for encapsulating the test execution, enables the catching of exceptions that are not derived from the standard exception (
std::exception
). - MfcTestRunner, a test runner based on the Microsoft Foundation Classes (MFC)
- QtTestRunner, a Qt 4 based graphical test runner
- CursesTestRunner, a curses- based test runner
- WxWidgetsTestRunner, a test runner based on wxWidgets
example
This example shows a unit test. The class Kalkulator
is the object to be tested, KalkulatorTest
the unit test. (The program start point must be modified to run the test.)
Great calculator
...
class Kalkulator
{
public:
// Berechne die Wurzel von k
double squareRoot(double k) { return sqrt(k); }
};
Class calculator test
#include <cppunit/extensions/HelperMacros.h>
class KalkulatorTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE( KalkulatorTest );
CPPUNIT_TEST( testSqrt );
CPPUNIT_TEST_SUITE_END();
public:
void testSqrt();
};
CPPUNIT_TEST_SUITE_REGISTRATION( KalkulatorTest );
void KalkulatorTest::testSqrt() {
Kalkulator kalk;
CPPUNIT_ASSERT(kalk.squareRoot(9) == 3);
}
Web links
- CppUnit Homepage (English)
- CppUnit Tutorial - Unit tests with C ++ ( Memento from March 17, 2016 in the Internet Archive )
Individual evidence
- ↑ cppunit.sourceforge.net October 25, 2006