Next: , Previous: Implementing test cases for a normal test module, Up: Using MIN for test cases implementation


2.6 Implementing test cases for a MINUnit test module

Implement a test case as a separate function to a <own_module_name>Cases.c file using the following type of function:

     MIN_TESTDEFINE(test_dllist_create)
     {
     MIN_ASSERT_NOT_EQUALS( l, 0 );
     }

The file consists of two sections TEST_VAR_DECLARATIONS and TEST_CASES.

Variables that are common for all test cases are defined in the TEST_VAR_DECLARATIONS section.

The TEST_CASES section contains test fixtures (MIN_SETUP and MIN_TEARDOWN) and the test cases (MIN_TESTDEFINE). Code placed in the MIN_SETUP is executed for each test case before the test case execution; and MIN_TEARDOWN after each test case. The MIN_SETUP section should be used to initialize the common variables and possible startup routines. Similarly MIN_TEARDOWN can be used for clean up routines (e.g., freeing memory).

Implementation of test case itself is done by adding new MIN_TESTDEFINE section to TEST_CASES section. Name of the new test cases is defined as a parameter for the macro. Needed test case functionality must be placed in this section (apart from setup and teardown activities).

The result of each test case is determined by using of one or several MIN_ASSERT_ macros. If any of the MIN_ASSERT_ macros discovers that the test case result is other than expected, test case result will be marked as failed.