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

cppunit::TestCase Class Reference

テストケース。
A single test object. More...

#include <TestCase.h>

Inheritance diagram for cppunit::TestCase::

cppunit::Test List of all members.

Public Methods

 TestCase (const char *name)
 コンストラクタ。. More...

virtual ~TestCase ()
 デストラクタ。. More...

virtual void run (TestResult *result)
 テストを実行し、結果を集める。
Run the test, collecting results.
More...


virtual int countTestCases () const
 テストケースの個数を返す。
Return the number of test cases invoked by run().
More...


virtual const char * getName () const
 テストの名前を返す。
Returns the test name.
More...


virtual cu_String toString () const
 文字列に変換する。
Description of the test, for diagnostic output.
More...


virtual void setUp ()
 テストを初期化する。
A hook for fixture set up.
More...


virtual void tearDown ()
 テストの後片付けをする。
A hook for fixture tear down.
More...



Protected Methods

void startTest (TestResult *result)
 TestResult にテストの開始を通知する。. More...

void endTest (TestResult *result)
 TestResult にテストの終了を通知する。. More...

void runBare ()
 実際にテストを実行する。. More...

virtual void runTest ()=0
 テストの内容を定義する。
All the work for runTest is deferred to subclasses.
More...


void addFailure (const cu_String &msg, const char *file, long line)
 テストの失敗を追加する。. More...

void addError (const cu_String &msg, const char *file, long line)
 エラーを追加する。. More...

bool assertEqualsImpl (int expected, int actual, const char *file, long line)
bool assertEqualsImpl (long expected, long actual, const char *file, long line)
bool assertEqualsImpl (double expected, double actual, const char *file, long line, double delta=0)
bool assertEqualsImpl (const char *expected, const char *actual, const char *file, long line)
template<class Ch, class Tr, class Alloc> bool assertEqualsImpl (const char *expected, const std::basic_string< Ch, Tr, Alloc > &actual, const char *file, long line)
template<class Ch, class Tr, class Alloc> bool assertEqualsImpl (const std::basic_string< Ch, Tr, Alloc > &expected, const char *actual, const char *file, long line)
template<class Ch, class Tr, class Alloc> bool assertEqualsImpl (const std::basic_string< Ch, Tr, Alloc > &expected, const std::basic_string< Ch, Tr, Alloc > &actual, const char *file, long line)

Static Protected Methods

bool equals (double x1, double x2, double delta=0)
bool equals (const char *s1, const char *s2)
cu_String notEqualsMessage (int expected, int actual)
cu_String notEqualsMessage (long expected, long actual)
cu_String notEqualsMessage (double expected, double actual)
cu_String notEqualsMessage (const char *expected, const char *actual)

Detailed Description

テストケース。
A single test object.

This class is used to implement a simple test case: define a subclass that overrides the runTest method.

A test case defines the fixture to run multiple tests. To define a test case, do the following:

  1. implement a subclass of TestCase
  2. the fixture is defined by instance variables
  3. initialize the fixture state by overriding setUp (i.e. construct the instance variables of the fixture)
  4. clean-up after a test by overriding tearDown.
Each test runs in its own fixture so there can be no side effects among test runs.
Here is an example:
 class MathTest : public TestCase {
   protected:
     int m_value1;
     int m_value2;

   public:
     explicit MathTest(const char* name) : TestCase(name) {}

     virtual void setUp() {
         m_value1 = 2;
         m_value2 = 3;
     }
 };
 

For each test implement a method which interacts with the fixture.
Verify the expected results with assertions specified by calling
TEST_ASSERT on the expression you want to test:

   public:
     void testAdd() {
         int result = m_value1 + m_value2;
         TEST_ASSERT(result == 5);
     }
 

Once the methods are defined you can run them. To do this, use a TestCaller.

     Test* test = new TEST_CALLER(MathTest, testAdd);
     TestResult result;
     test->run(&result);
 

The tests to be run can be collected into a TestSuite.

   public:
     static Test* MathTest::suite() {
         TestSuite* suite = new TestSuite("MathTest");
         suite->addTest(new TEST_CALLER(MathTest, testAdd));
         suite->addTest(new TEST_CALLER(MathTest, testDivideByZero));
         return suite;
     }
 

See also:
TestSuite , TestCaller , TestResult


Constructor & Destructor Documentation

cppunit::TestCase::TestCase const char *    name [explicit]
 

コンストラクタ。.

Parameters:
name  テストの名前。

virtual cppunit::TestCase::~TestCase   [virtual]
 

デストラクタ。.


Member Function Documentation

virtual void cppunit::TestCase::run TestResult   result [virtual]
 

テストを実行し、結果を集める。
Run the test, collecting results.

Parameters:
result  テスト結果。

Reimplemented from cppunit::Test.

virtual int cppunit::TestCase::countTestCases   const [virtual]
 

テストケースの個数を返す。
Return the number of test cases invoked by run().

The base unit of testing is the class TestCase.
This method returns the number of TestCase objects invoked by the run() method.

Reimplemented from cppunit::Test.

virtual const char* cppunit::TestCase::getName   const [virtual]
 

テストの名前を返す。
Returns the test name.

Each test has a name. This name may be used to find the test in a suite of tests.

Reimplemented from cppunit::Test.

virtual cu_String cppunit::TestCase::toString   const [virtual]
 

文字列に変換する。
Description of the test, for diagnostic output.

The test description will typically include the test name, but may have additional description.
For example, a test suite named ComplexTest may be described as suite ComplexTest.

Reimplemented from cppunit::Test.

virtual void cppunit::TestCase::setUp   [inline, virtual]
 

テストを初期化する。
A hook for fixture set up.

virtual void cppunit::TestCase::tearDown   [inline, virtual]
 

テストの後片付けをする。
A hook for fixture tear down.

void cppunit::TestCase::startTest TestResult   result [protected]
 

TestResult にテストの開始を通知する。.

void cppunit::TestCase::endTest TestResult   result [protected]
 

TestResult にテストの終了を通知する。.

void cppunit::TestCase::runBare   [protected]
 

実際にテストを実行する。.

virtual void cppunit::TestCase::runTest   [protected, pure virtual]
 

テストの内容を定義する。
All the work for runTest is deferred to subclasses.

void cppunit::TestCase::addFailure const cu_String &    msg,
const char *    file,
long    line
[protected]
 

テストの失敗を追加する。.

Parameters:
msg  メッセージ。
file  発生したファイル名。
line  発生した行番号。

void cppunit::TestCase::addError const cu_String &    msg,
const char *    file,
long    line
[protected]
 

エラーを追加する。.

Parameters:
msg  メッセージ。
file  発生したファイル名。
line  発生した行番号。

bool cppunit::TestCase::assertEqualsImpl int    expected,
int    actual,
const char *    file,
long    line
[protected]
 

bool cppunit::TestCase::assertEqualsImpl long    expected,
long    actual,
const char *    file,
long    line
[protected]
 

bool cppunit::TestCase::assertEqualsImpl double    expected,
double    actual,
const char *    file,
long    line,
double    delta = 0
[protected]
 

bool cppunit::TestCase::assertEqualsImpl const char *    expected,
const char *    actual,
const char *    file,
long    line
[protected]
 

template<class Ch, class Tr, class Alloc>
bool cppunit::TestCase::assertEqualsImpl const char *    expected,
const std::basic_string< Ch, Tr, Alloc > &    actual,
const char *    file,
long    line
[inline, protected]
 

template<class Ch, class Tr, class Alloc>
bool cppunit::TestCase::assertEqualsImpl const std::basic_string< Ch, Tr, Alloc > &    expected,
const char *    actual,
const char *    file,
long    line
[inline, protected]
 

template<class Ch, class Tr, class Alloc>
bool cppunit::TestCase::assertEqualsImpl const std::basic_string< Ch, Tr, Alloc > &    expected,
const std::basic_string< Ch, Tr, Alloc > &    actual,
const char *    file,
long    line
[inline, protected]
 

bool cppunit::TestCase::equals double    x1,
double    x2,
double    delta = 0
[static, protected]
 

bool cppunit::TestCase::equals const char *    s1,
const char *    s2
[static, protected]
 

cu_String cppunit::TestCase::notEqualsMessage int    expected,
int    actual
[static, protected]
 

cu_String cppunit::TestCase::notEqualsMessage long    expected,
long    actual
[static, protected]
 

cu_String cppunit::TestCase::notEqualsMessage double    expected,
double    actual
[static, protected]
 

cu_String cppunit::TestCase::notEqualsMessage const char *    expected,
const char *    actual
[static, protected]
 


The documentation for this class was generated from the following file:
Generated on Sun Mar 31 23:42:08 2002 for CppUnit-x by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001