[ CCUnit project page ] |  | [ CCUnit home page ]

Data Fields

# CCUnitTestCase Struct Reference
[TestCase, Writing Test Case]

Wraps a test case with setUp and tearDown function. More...

`#include <CCUnitTestCase.h>`

Collaboration diagram for CCUnitTestCase:
[legend]

## Data Fields
CCUnitTest | test
| super class
const char * | name
| test case name
CCUnitTestFunc * | setup_setUp
| setUp for a case
CCUnitTestFunc * | setup_tearDown
| tearDown for a case
CCUnitTestFunc * | setUp
| setUp for each cases
CCUnitTestFunc * | tearDown
| tearDown for each cases
CCUnitList | testFuncs
| test functions

## Detailed Description

Wraps a test case with setUp and tearDown function.

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

To define a test case, do the following:

- the case is defined by static variables
- initialize the case state by setUp function
- clean-up after a test by tearDown function

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;
     }

     ...

     CCUnitTestCase* MathTest_newTestCase ()
     {
       return ccunit_newTestCase ("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 ("testAdd", "add test", testAdd);
     }

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

     CCUintTestSuite* MathTest_suite ()
     {
       CCUnitTestSuite* suite = ccunit_newTestSuite ("MathTest");
       CCUnitTestCase* tcase = MathTest_newTestCase ();
       ccunit_addTestCase (suite, tcase);
       ccunit_addTestCase (tcase, MathTest_newTestCase_testAdd ());
       ccunit_addTestCase (tcase, 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, MakeSuite,

## Field Documentation

const char* CCUnitTestCase::name

test case name

Referenced by ccunit_newTestCase(), and destroy().

CCUnitTestFunc* CCUnitTestCase::setUp

setUp for each cases

Referenced by ccunit_addTestFunc(), destroy(), and run().

CCUnitTestFunc* CCUnitTestCase::setup_setUp

setUp for a case

Referenced by ccunit_addTestFunc(), destroy(), and run().

CCUnitTestFunc* CCUnitTestCase::setup_tearDown

tearDown for a case

Referenced by ccunit_addTestFunc(), destroy(), and run().

CCUnitTestFunc* CCUnitTestCase::tearDown

tearDown for each cases

Referenced by ccunit_addTestFunc(), destroy(), and run().

CCUnitTest CCUnitTestCase::test

super class

Referenced by ccunit_deleteTestCase(), ccunit_newTestCase(), and ccunit_runTestCase().

CCUnitList CCUnitTestCase::testFuncs

test functions

Referenced by ccunit_addTestFunc(), ccunit_newTestCase(), destroy(), and run().

The documentation for this struct was generated from the following file:

- CCUnitTestCase.h

| hosts this site. |  | Send comments to: CCUnit Developer |