1
#ifndef CPPUNIT_TESTFIXTURE_H // -*- C++ -*-
2
#define CPPUNIT_TESTFIXTURE_H
4
#include <cppunit/Portability.h>
9
/*! \brief Wraps a test case with setUp and tearDown methods.
10
* \ingroup WritingTestFixture
12
* A TestFixture is used to provide a common environment for a set
15
* To define a test fixture, do the following:
16
* - implement a subclass of TestCase
17
* - the fixture is defined by instance variables
18
* - initialize the fixture state by overriding setUp
19
* (i.e. construct the instance variables of the fixture)
20
* - clean-up after a test by overriding tearDown.
22
* Each test runs in its own fixture so there
23
* can be no side effects among test runs.
27
* class MathTest : public CppUnit::TestFixture {
29
* int m_value1, m_value2;
41
* For each test implement a method which interacts
42
* with the fixture. Verify the expected results with assertions specified
43
* by calling CPPUNIT_ASSERT on the expression you want to test:
48
* int result = m_value1 + m_value2;
49
* CPPUNIT_ASSERT( result == 5 );
53
* Once the methods are defined you can run them. To do this, use
57
* CppUnit::Test *test = new CppUnit::TestCaller<MathTest>( "testAdd",
58
* &MathTest::testAdd );
63
* The tests to be run can be collected into a TestSuite.
67
* static CppUnit::TestSuite *MathTest::suite () {
68
* CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite;
69
* suiteOfTests->addTest(new CppUnit::TestCaller<MathTest>(
70
* "testAdd", &MathTest::testAdd));
71
* suiteOfTests->addTest(new CppUnit::TestCaller<MathTest>(
72
* "testDivideByZero", &MathTest::testDivideByZero));
73
* return suiteOfTests;
77
* A set of macros have been created for convenience. They are located in HelperMacros.h.
79
* \see TestResult, TestSuite, TestCaller,
80
* \see CPPUNIT_TEST_SUB_SUITE, CPPUNIT_TEST, CPPUNIT_TEST_SUITE_END,
81
* \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_EXCEPTION, CPPUNIT_TEST_FAIL.
83
class CPPUNIT_API TestFixture
86
virtual ~TestFixture() {};
88
//! \brief Set up context before running a test.
89
virtual void setUp() {};
91
//! Clean up after the test run.
92
virtual void tearDown() {};