| 1 |
<HTML> |
| 2 |
<HEAD> |
| 3 |
<TITLE>CUnit - Introduction</TITLE> |
| 4 |
<LINK REL=StyleSheet HREF="CUnit_doc.css" TYPE="text/css" TITLE="CUnit Basic Style" /> |
| 5 |
</HEAD> |
| 6 |
<BODY> |
| 7 |
<DIV CLASS="NAVHEADER" > |
| 8 |
<TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0"> |
| 9 |
<TR> |
| 10 |
<TH COLSPAN="3" ALIGN="center"><H3>CUnit Progammers Guide</H3></TH> |
| 11 |
</TR> |
| 12 |
<TR> |
| 13 |
<TD WIDTH="10%" ALIGN="left" VALIGN="bottom"><A HREF="index.html" ACCESSKEY="P" >Prev</A></TD> |
| 14 |
<TD WIDTH="80%" ALIGN="center" VALIGN="bottom"><A HREF="index.html" ACCESSKEY="H" >Home</A></TD> |
| 15 |
<TD WIDTH="10%" ALIGN="right" VALIGN="bottom"><A HREF="writing_tests.html" ACCESSKEY="N" >Next</A></TD> |
| 16 |
</TR> |
| 17 |
</TABLE> |
| 18 |
<HR ALIGN="LEFT" WIDTH="100%"> |
| 19 |
|
| 20 |
<H2>1. Introduction to Unit Testing with CUnit</H2> |
| 21 |
|
| 22 |
<H3 ID="description">1.1. Description</H3> |
| 23 |
CUnit is a system for writing, administering, and running unit tests in C. |
| 24 |
It is built as a library (static or dynamic) which is linked with the |
| 25 |
user's testing code. |
| 26 |
<P /> |
| 27 |
CUnit uses a simple framework for building test structures, and provides a |
| 28 |
rich set of assertions for testing common data types. In addition, several |
| 29 |
different interfaces are provided for running tests and reporting results. |
| 30 |
These include automated interfaces for code-controlled testing and reporting, |
| 31 |
as well as interactive interfaces allowing the user to run tests and view |
| 32 |
results dynamically. |
| 33 |
<P /> |
| 34 |
The data types and functions useful to the typical user are declared in the following header files: |
| 35 |
<P /> |
| 36 |
<TABLE CELLPADDING=4> |
| 37 |
<TR VALIGN="top"> |
| 38 |
<TH><U>Header File</U></TH> |
| 39 |
<TH><U>Description</U></TH> |
| 40 |
</TR> |
| 41 |
<TR VALIGN="top"> |
| 42 |
<TD><B>#include <<A HREF="headers/CUnit.h">CUnit/CUnit.h</A>></B></TD> |
| 43 |
<TD>ASSERT macros for use in test cases, and includes other framework headers.</TD> |
| 44 |
</TR> |
| 45 |
<TR VALIGN="top"> |
| 46 |
<TD><B>#include <<A HREF="headers/CUError.h">CUnit/CUError.h</A>></B></TD> |
| 47 |
<TD>Error handing functions and data types. <I>Included automatically by CUnit.h.</I></TD> |
| 48 |
</TR> |
| 49 |
<TR VALIGN="top"> |
| 50 |
<TD><B>#include <<A HREF="headers/TestDB.h">CUnit/TestDB.h</A>></B></TD> |
| 51 |
<TD>Data type definitions and manipulation functions for the test registry, suites, and tests. |
| 52 |
<I>Included automatically by CUnit.h.</I> |
| 53 |
</TD> |
| 54 |
</TR> |
| 55 |
<TR VALIGN="top"> |
| 56 |
<TD><B>#include <<A HREF="headers/TestRun.h">CUnit/TestRun.h</A>></B></TD> |
| 57 |
<TD>Data type definitions and functions for running tests and retrieving results. |
| 58 |
<I>Included automatically by CUnit.h.</I> |
| 59 |
</TD> |
| 60 |
</TR> |
| 61 |
<TR VALIGN="top"> |
| 62 |
<TD><B>#include <<A HREF="headers/Automated.h">CUnit/Automated.h</A>></B></TD> |
| 63 |
<TD>Automated interface with xml output.</TD> |
| 64 |
</TR> |
| 65 |
<TR VALIGN="top"> |
| 66 |
<TD><B>#include <<A HREF="headers/Basic.h">CUnit/Basic.h</A>></B></TD> |
| 67 |
<TD>Basic interface with non-interactive output to stdout.</TD> |
| 68 |
</TR> |
| 69 |
<TR VALIGN="top"> |
| 70 |
<TD><B>#include <<A HREF="headers/Console.h">CUnit/Console.h</A>></B></TD> |
| 71 |
<TD>Interactive console interface.</TD> |
| 72 |
</TR> |
| 73 |
<TR VALIGN="top"> |
| 74 |
<TD><B>#include <<A HREF="headers/CUCurses.h">CUnit/CUCurses.h</A>></B></TD> |
| 75 |
<TD>Interactive console interface (*nix).</TD> |
| 76 |
</TR> |
| 77 |
<TR VALIGN="top"> |
| 78 |
<TD><B>#include <<A HREF="headers/Win.h">CUnit/Win.h</A>></B></TD> |
| 79 |
<TD>Windows interface (not yet implemented).</TD> |
| 80 |
</TR> |
| 81 |
</TABLE> |
| 82 |
|
| 83 |
<H3 ID="structure">1.2. Structure</H3> |
| 84 |
CUnit is a combination of a platform-independent framework with various |
| 85 |
user interfaces. The core framework provides basic support for managing |
| 86 |
a test registry, suites, and test cases. The user interfaces facilitate |
| 87 |
interaction with the framework to run tests and view results. |
| 88 |
<P /> |
| 89 |
CUnit is organized like a conventional unit testing framework: |
| 90 |
<PRE> |
| 91 |
Test Registry |
| 92 |
| |
| 93 |
------------------------------ |
| 94 |
| | |
| 95 |
Suite '1' . . . . Suite 'N' |
| 96 |
| | |
| 97 |
--------------- --------------- |
| 98 |
| | | | |
| 99 |
Test '11' ... Test '1M' Test 'N1' ... Test 'NM' |
| 100 |
</PRE> |
| 101 |
Individual test cases are packaged into suites, which are registered |
| 102 |
with the active test registry. Suites can have setup and teardown |
| 103 |
functions which are automatically called before and after running the |
| 104 |
suite's tests. All suites/tests in the registry may be run using a |
| 105 |
single function call, or selected suites or tests can be run. |
| 106 |
<H3 ID="usage">1.3. General Usage</H3> |
| 107 |
A typical sequence of steps for using the CUnit framework is: |
| 108 |
<OL> |
| 109 |
<LI><A HREF="writing_tests.html">Write functions</A> for tests (and suite init/cleanup if necessary).</LI> |
| 110 |
<LI>Initialize the test registry - <A HREF="test_registry.html#init">CU_initialize_registry()</A></LI> |
| 111 |
<LI>Add suites to the test registry - <A HREF="managing_tests.html#addsuite">CU_add_suite()</A></LI> |
| 112 |
<LI>Add tests to the suites - <A HREF="managing_tests.html#addtest">CU_add_test()</A></LI> |
| 113 |
<LI>Run tests using an appropriate interface, e.g. <A HREF="running_tests.html#console">CU_console_run_tests</A></LI> |
| 114 |
<LI>Cleanup the test registry - <A HREF="test_registry.html#cleanup">CU_cleanup_registry</A></LI> |
| 115 |
</OL> |
| 116 |
|
| 117 |
<H3 ID="changes">1.4. Changes to the CUnit API in Version 2</H3> |
| 118 |
All public names in CUnit are now prefixed with 'CU_'. This helps |
| 119 |
minimize clashes with names in user code. Note that earlier versions |
| 120 |
of CUnit used different names without this prefix. The older API names |
| 121 |
are deprecated but still supported. To use the older names, user code |
| 122 |
must now be compiled with <CITE>USE_DEPRECATED_CUNIT_NAMES</CITE> defined. |
| 123 |
<P /> |
| 124 |
The deprecated API functions are described in the appropriate sections of |
| 125 |
the documentation. |
| 126 |
|
| 127 |
<DIV CLASS="NAVFOOTER"> |
| 128 |
<HR ALIGN="LEFT" WIDTH="100%"> |
| 129 |
<TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0"> |
| 130 |
<TR> |
| 131 |
<TD WIDTH="33%" ALIGN="left" VALIGN="top"><A HREF="index.html" ACCESSKEY="P">Prev</A></TD> |
| 132 |
<TD WIDTH="34%" ALIGN="center" VALIGN="top"><A HREF="index.html" ACCESSKEY="H" >Home</A></TD> |
| 133 |
<TD WIDTH="33%" ALIGN="right" VALIGN="top"><A HREF="writing_tests.html" ACCESSKEY="N" >Next</A></TD> |
| 134 |
</TR> |
| 135 |
<TR> |
| 136 |
<TD WIDTH="33%" ALIGN="left" VALIGN="top">Table of Contents</TD> |
| 137 |
<TD WIDTH="34%" ALIGN="center" VALIGN="top"> </TD> |
| 138 |
<TD WIDTH="33%" ALIGN="right" VALIGN="top">Writing CUnit Test Cases</TD> |
| 139 |
</TR> |
| 140 |
</TABLE> |
| 141 |
</DIV> |
| 142 |
|
| 143 |
</BODY> |
| 144 |
</HTML> |