BCUnit - Introduction

### BCUnit Progammers Guide
Prev | Home | Next

## 1. Introduction to Unit Testing with BCUnit

### 1.1. Description

BCUnit is a system for writing, administering, and running unit tests in C. It is built as a library (static or dynamic) which is linked with the user's testing code.

BCUnit uses a simple framework for building test structures, and provides a rich set of assertions for testing common data types. In addition, several different interfaces are provided for running tests and reporting results. These include automated interfaces for code-controlled testing and reporting, as well as interactive interfaces allowing the user to run tests and view results dynamically.

The data types and functions useful to the typical user are declared in the following header files:

Header File | Description
--- | ---
#include <BCUnit/BCUnit.h> | ASSERT macros for use in test cases, and includes other framework headers.
#include <BCUnit/CUError.h> | Error handing functions and data types. Included automatically by BCUnit.h.
#include <BCUnit/TestDB.h> | Data type definitions and manipulation functions for the test registry, suites, and tests. Included automatically by BCUnit.h.
#include <BCUnit/TestRun.h> | Data type definitions and functions for running tests and retrieving results. Included automatically by BCUnit.h.
#include <BCUnit/Automated.h> | Automated interface with xml output.
#include <BCUnit/Basic.h> | Basic interface with non-interactive output to stdout.
#include <BCUnit/Console.h> | Interactive console interface.
#include <BCUnit/CUCurses.h> | Interactive console interface (*nix).
#include <BCUnit/Win.h> | Windows interface (not yet implemented).

### 1.2. Structure

BCUnit is a combination of a platform-independent framework with various user interfaces. The core framework provides basic support for managing a test registry, suites, and test cases. The user interfaces facilitate interaction with the framework to run tests and view results.

BCUnit is organized like a conventional unit testing framework:

                          Test Registry
                                |
                 ------------------------------
                 |                            |
              Suite '1'      . . . .       Suite 'N'
                 |                            |
           ---------------             ---------------
           |             |             |             |
        Test '11' ... Test '1M'     Test 'N1' ... Test 'NM'

Individual test cases are packaged into suites, which are registered with the active test registry. Suites can have setup and teardown functions which are automatically called before and after running the suite's tests. All suites/tests in the registry may be run using a single function call, or selected suites or tests can be run.

### 1.3. General Usage

A typical sequence of steps for using the BCUnit framework is:

1. Write functions for tests (and suite init/cleanup if necessary).
2. Initialize the test registry - CU_initialize_registry()
3. Add suites to the test registry - CU_add_suite()
4. Add tests to the suites - CU_add_test()
5. Run tests using an appropriate interface, e.g. CU_console_run_tests
6. Cleanup the test registry - CU_cleanup_registry

### 1.4. Changes to the BCUnit API in Version 2

All public names in BCUnit are now prefixed with 'CU_'. This helps minimize clashes with names in user code. Note that earlier versions of BCUnit used different names without this prefix. The older API names are deprecated but still supported. To use the older names, user code must now be compiled with USE_DEPRECATED_BCUNIT_NAMES defined.

The deprecated API functions are described in the appropriate sections of the documentation.

Prev | Home | Next
Table of Contents |  | Writing BCUnit Test Cases