CCUnit project page CCUnit home page

Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

CCUnitTestFixture Struct Reference
[TestFixtureWriting test fixture]

#include <CCUnitTestFixture.h>

Collaboration diagram for CCUnitTestFixture:

Collaboration graph
[legend]

Detailed Description

Wraps a test case with setUp and tearDown methods.

A TestCase is used to provide a common environment for a set of test cases.

To define a test case, do the following:

Each test runs in its own case so there can be no side effects among test runs. Here is an example:

 static int value1, value2;

 void setUp_MathTest ()
 {
   value1 = 2;
   value2 = 3;
 }

 ...

 CCUnitTestFixture* MathTest_newTestFixture ()
 {
   return ccunit_newTestFixture ("MathTest", setUp_MathTest, NULL);
 }

For each test implement a function which interacts with the case. Verify the expected results with assertions specified by calling CCUNIT_ASSERT on the expression you want to test:

 void testAdd ()
 {
   int result = value1 + value2;
   CCUNIT_ASSERT (result == 5);
 }

 ...

 void MathTest_newTestCase_testAdd ()
 {
   return ccunit_newTestCase ("addTest", "add test", addTest);
 }

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

 CCUintTestSuite* MathTest_suite ()
 {
   CCUnitTestSuite* suite = ccunit_newTestSuite ("MathTest");
   CCUnitTestFixture* fixture = MathTest_newTestFixture ();
   ccunit_addTestFixture (suite, fixture);
   ccunit_addTestCase (fixture, MathTest_newTestCase_testAdd ());
   ccunit_addTestCase (fixture, MathTest_newTestCase_testDivZero ())
   return suite;
 }

Once the functions are defined you can run them. To do this, use a TestRunner.

   CCUnitTestRunner *runner = ccunit_newTestRunner (stdout);
   CCUnitTestSuite *suite = MathTest_suite ();
   runner->run (runner, suite);

A command line tool have been created for convenience. It is located in src/tools/ccunit_makeSuite.c.

See also:
CCUnitTestResult, CCUnitTestCase, CCUnitTestSuite, CCUnitMakeSuite,


Data Fields

CCUnitTest test
 super class

const char * name
 test fixture name

CCUnitTestFuncsetUp
 setUp function

CCUnitTestFunctearDown
 tearDown function

CCUnitList testCases
 test cases


Field Documentation

const char* CCUnitTestFixture::name
 

test fixture name

CCUnitTestFunc* CCUnitTestFixture::setUp
 

setUp function

CCUnitTestFunc* CCUnitTestFixture::tearDown
 

tearDown function

CCUnitTest CCUnitTestFixture::test
 

super class

CCUnitList CCUnitTestFixture::testCases
 

test cases


The documentation for this struct was generated from the following file:
SourceForge.jp hosts this site. Send comments to:
CCUnit Developer