CUnit Progammers Guide |
||
---|---|---|
Prev | Home | Next |
void CU_automated_run_tests(void) CU_ErrorCode CU_list_tests_to_file(void) void CU_set_output_filename(const char* szFilenameRoot)#include <CUnit/Basic.h>
typedef enum CU_BasicRunMode CU_ErrorCode CU_basic_run_tests(void) CU_ErrorCode CU_basic_run_suite(CU_pSuite pSuite) CU_ErrorCode CU_basic_run_test(CU_pSuite pSuite, CU_pTest pTest) void CU_basic_set_mode(CU_BasicRunMode mode) CU_BasicRunMode CU_basic_get_mode(void) void CU_basic_show_failures(CU_pFailureRecord pFailure)#include <CUnit/Console.h>
void CU_console_run_tests(void)#include <CUnit/CUCurses.h>
void CU_curses_run_tests(void)#include <CUnit/TestRun.h> (included automatically by <CUnit/CUnit.h>)
unsigned int CU_get_number_of_suites_run(void) unsigned int CU_get_number_of_suites_failed(void) unsigned int CU_get_number_of_tests_run(void) unsigned int CU_get_number_of_tests_failed(void) unsigned int CU_get_number_of_asserts(void) unsigned int CU_get_number_of_successes(void) unsigned int CU_get_number_of_failures(void) typedef struct CU_RunSummary typedef CU_Runsummary* CU_pRunSummary const CU_pRunSummary CU_get_run_summary(void) typedef struct CU_FailureRecord typedef CU_FailureRecord* CU_pFailureRecord const CU_pFailureRecord CU_get_failure_list(void) unsigned int CU_get_number_of_failure_records(void) void CU_set_fail_on_inactive(CU_BOOL new_inactive) CU_BOOL CU_get_fail_on_inactive(void)
Interface | Platform | Description |
Automated | all | non-interactive with output to xml files |
Basic | all | non-interactive with optional output to stdout |
Console | all | interactive console mode under user control |
Curses | Linux/Unix | interactive curses mode under user control |
void CU_automated_run_tests(void)
Runs all tests in all registered (and active) suites. Test results
are output to a file named ROOT-Results.xml. The filename ROOT can
be set using CU_set_output_filename(), or else the default
CUnitAutomated-Results.xml is used. Note that if a distict filename ROOT
is not set before each run, the results file will be overwritten.
The results file is supported by both a document type definition
file (CUnit-Run.dtd) and XSL stylesheet (CUnit-Run.xsl).
These are provided in the Share subdirectory of the source and installation
trees.
CU_ErrorCode CU_list_tests_to_file(void)
Lists the registered suites and associated tests to file.
The listing file is named ROOT-Listing.xml. The filename ROOT
can be set using CU_set_output_filename(), or else the default
CUnitAutomated is used. Note that if a distict filename ROOT
is not set before each run, the listing file will be overwritten.
The listing file is supported by both a document type definition
file (CUnit-List.dtd) and XSL stylesheet (CUnit-List.xsl).
These are provided in the Share subdirectory of the source and installation
trees.
Note also that a listing file is not generated automatically by
CU_automated_run_tests(). Client code must explicitly request a
listing when one is desired.
void CU_set_output_filename(const char* szFilenameRoot)
Sets the output filenames for the results and listing files. szFilenameRoot is used to construct the filenames by appending -Results.xml and -Listing.xml, respectively.
CU_ErrorCode CU_basic_run_tests(void)
Runs all tests in all registered suites. Only active suites are executed, and it is not considered an error if inactive suites are encountered and skipped. Returns the 1st error code occurring during the test run. The type of output is controlled by the current run mode, which can be set using CU_basic_set_mode().
CU_ErrorCode CU_basic_run_suite(CU_pSuite pSuite)
Runs all tests in single specified suite. Returns the 1st
error code occurring during the test run. CU_basic_run_suite itself
sets CUE_NOSUITE if pSuite is NULL
and
CUE_SUITE_INACTIVE if pSuite is not active for execution.
The type of output is controlled by the current run mode, which can be set using
CU_basic_set_mode().
CU_ErrorCode CU_basic_run_test(CU_pSuite pSuite, CU_pTest pTest)
Runs a single test in a specified suite. Returns the 1st
error code occurring during the test run. CU_basic_run_test itself
sets CUE_NOSUITE if pSuite is NULL
, CUE_NOTEST
if pTest is NULL
, CUE_SUITE_INACTIVE if pSuite is not
active, CUE_TEST_NOT_IN_SUITE if pTest is not a registered test in
pSuite, and CUE_TEST_INACTIVE if pTest is not active. The type of
output is controlled by the current run mode, which can be set using
CU_basic_set_mode().
void CU_basic_set_mode(CU_BasicRunMode mode)
Sets the basic run mode, which controls the output during test runs. Choices are:
CU_BRM_NORMAL | Failures and run summary are printed. |
CU_BRM_SILENT | No output is printed except error messages. |
CU_BRM_VERBOSE | Maximum output of run details. |
CU_BasicRunMode CU_basic_get_mode(void)
Retrieves the current basic run mode code.
void CU_basic_show_failures(CU_pFailureRecord pFailure)
Prints a summary of all failures to stdout. Does not depend on the run mode.
void CU_console_run_tests(void)
void CU_curses_run_tests(void)
void CU_set_fail_on_inactive(CU_BOOL new_inactive)
CU_BOOL CU_get_fail_on_inactive(void)
The default runtime behavior is for inactive suites and
tests to be reported as failures. This is so the client is aware that their
test structure has been partially deactivated. If the client prefers to have
inactive suites and tests ignored, the behavior can be modified using these
functions. A value of CU_FALSE
indicates that the framework
will ignore inactive entities; CU_TRUE
will have them treated as
failures.
unsigned int CU_get_number_of_suites_run(void)
unsigned int CU_get_number_of_suites_failed(void)
unsigned int CU_get_number_of_tests_run(void)
unsigned int CU_get_number_of_tests_failed(void)
unsigned int CU_get_number_of_asserts(void)
unsigned int CU_get_number_of_successes(void)
unsigned int CU_get_number_of_failures(void)
These functions report the number of suites, tests, and
assertions that ran or failed during the last run. A suite is considered failed
if its initialization or cleanup function returned non-NULL
, or if
it was inactive and the framework was set to treat
inactive suites/tests as failures. A test fails if any of its assertions
failed or if it was inactive under the same conditions. The last 3 functions
all refer to individual assertions. An inactive suite (or test) is not counted
among the number of suites (tests) run. A consequence of this is that a suite
(or test) can fail even though it is not reported as having been run.
To retrieve the total number of registered suites and tests, use
CU_get_registry()−>uiNumberOfSuites
and CU_get_registry()−>uiNumberOfTests,
respectively.
const CU_pRunSummary CU_get_run_summary(void)
Retrieves all test result counts at once. The return value is a pointer to a saved structure containing the counts. This data type is defined in <CUnit/TestRun.h> (included automatically by <CUnit/CUnit.h>):
typedef struct CU_RunSummary { unsigned int nSuitesRun; unsigned int nSuitesFailed; unsigned int nTestsRun; unsigned int nTestsFailed; unsigned int nAsserts; unsigned int nAssertsFailed; unsigned int nFailureRecords; } CU_RunSummary; typedef CU_Runsummary* CU_pRunSummary;
The structure variable associated with the returned pointer is owned by the framework, so the user should not free or otherwise change it. Note that the pointer may be invalidated once another test run is initiated.
const CU_pFailureRecord CU_get_failure_list(void)
Retrieves a linked list recording any failures occurring during the
last test run (NULL
for no failures). The data type of the return value
is declared in <CUnit/TestRun.h> (included
automatically by <CUnit/CUnit.h>). Each failure
record contains information about the location and nature of the failure:
typedef struct CU_FailureRecord { unsigned int uiLineNumber; char* strFileName; char* strCondition; CU_pTest pTest; CU_pSuite pSuite; struct CU_FailureRecord* pNext; struct CU_FailureRecord* pPrev; } CU_FailureRecord; typedef CU_FailureRecord* CU_pFailureRecord;
The structure variable associated with the returned pointer is owned by the framework, so the user should not free or otherwise change it. Note that the pointer may be invalidated once another test run is initiated.
unsigned int CU_get_number_of_failure_records(void)
Retrieves the number of CU_FailureRecords in the linked list of failures returned by CU_get_failure_list(). Note that this can be more than the number of failed assertions, since suite initialization and cleanup failures are included.
Deprecated Name | Equivalent New Name |
automated_run_tests() |
CU_automated_run_tests() plus CU_list_tests_to_file() |
set_output_filename() |
CU_set_output_filename() |
console_run_tests() |
CU_console_run_tests() |
curses_run_tests() |
CU_curses_run_tests() |