?? running_tests.html
字號:
<HTML><HEAD> <TITLE>CUnit - Running Tests</TITLE> <LINK REL=StyleSheet HREF="CUnit_doc.css" TYPE="text/css" TITLE="CUnit Basic Style" /></HEAD><BODY><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0"> <TR> <TH COLSPAN="3" ALIGN="center"><H3>CUnit Progammers Guide</H3></TH> </TR> <TR> <TD WIDTH="10%" ALIGN="left" VALIGN="bottom"><A HREF="managing_tests.html" ACCESSKEY="P" >Prev</A></TD> <TD WIDTH="80%" ALIGN="center" VALIGN="bottom"><A HREF="index.html" ACCESSKEY="H" >Home</A></TD> <TD WIDTH="10%" ALIGN="right" VALIGN="bottom"><A HREF="error_handling.html" ACCESSKEY="N" >Next</A></TD> </TR></TABLE><HR ALIGN="LEFT" WIDTH="100%"><H2>5. Running Tests</H2><H3 ID="synopsis">5.1. Synopsis</H3>#include <<A HREF="headers/Automated.h">CUnit/Automated.h</A>><PRE> void <A HREF="#automated">CU_automated_run_tests</A>(void) CU_ErrorCode <A HREF="#automated">CU_list_tests_to_file</A>(void) void <A HREF="#automated">CU_set_output_filename</A>(const char* szFilenameRoot)</PRE><P />#include <<A HREF="headers/basic.h">CUnit/Basic.h</A>><PRE> typedef enum <A HREF="#basic">CU_BasicRunMode</A> CU_ErrorCode <A HREF="#basic">CU_basic_run_tests</A>(void) CU_ErrorCode <A HREF="#basic">CU_basic_run_suite</A>(CU_pSuite pSuite) CU_ErrorCode <A HREF="#basic">CU_basic_run_test</A>(CU_pSuite pSuite, CU_pTest pTest) void <A HREF="#basic">CU_basic_set_mode</A>(CU_BasicRunMode mode) CU_BasicRunMode <A HREF="#basic">CU_basic_get_mode</A>(void) void <A HREF="#basic">CU_basic_show_failures</A>(CU_pFailureRecord pFailure)</PRE><P />#include <<A HREF="headers/Console.h">CUnit/Console.h</A>><PRE> void <A HREF="#console">CU_console_run_tests</A>(void)</PRE><P />#include <<A HREF="headers/CUCurses.h">CUnit/CUCurses.h</A>><PRE> void <A HREF="#curses">CU_curses_run_tests</A>(void)</PRE><P />#include <<A HREF="headers/TestRun.h">CUnit/TestRun.h</A>>(included automatically by <<A HREF="headers/CUnit.h">CUnit/CUnit.h</A>>)<PRE> unsigned int <A HREF="#results">CU_get_number_of_suites_run</A>(void) unsigned int <A HREF="#results">CU_get_number_of_suites_failed</A>(void) unsigned int <A HREF="#results">CU_get_number_of_tests_run</A>(void) unsigned int <A HREF="#results">CU_get_number_of_tests_failed</A>(void) unsigned int <A HREF="#results">CU_get_number_of_asserts</A>(void) unsigned int <A HREF="#results">CU_get_number_of_successes</A>(void) unsigned int <A HREF="#results">CU_get_number_of_failures</A>(void) typedef struct <A HREF="#results">CU_RunSummary</A> typedef CU_Runsummary* <A HREF="#results">CU_pRunSummary</A> const CU_pRunSummary <A HREF="#results">CU_get_run_summary</A>(void) typedef struct <A HREF="#results">CU_FailureRecord</A> typedef CU_FailureRecord* <A HREF="#results">CU_pFailureRecord</A> const CU_pFailureRecord <A HREF="#results">CU_get_failure_list</A>(void) unsigned int <A HREF="#results">CU_get_number_of_failure_records</A>(void)</PRE><P /><H3 ID="overview">5.2. Running Tests in CUnit</H3>CUnit supports running all tests in all registered suites, but individual testsor suites can also be run. During each run, the framework keeps track of the number of suites, tests, and assertions run, passed, and failed. Note that theresults are cleared each time a test run is initiated (even if it fails).<P />While CUnit provides primitive functions for running suites and tests, mostusers will want to use one of the simplified user interfaces. Theseinterfaces handle the details of interaction with the framework and provideoutput of test details and results for the user.<P />The following interfaces are included in the CUnit library:<P CLASS="indent5"><TABLE CELLPADDING=3 BORDER=1> <TR> <TD><B>Interface</B></TD> <TD ALIGN="center"><B>Platform</B></TD> <TD><B>Description</B></TD> </TR> <TR> <TD><A HREF="#automated">Automated</A></TD> <TD ALIGN="center">all</TD> <TD>non-interactive with output to xml files</TD> </TR> <TR> <TD><A HREF="#basic">Basic</A></TD> <TD ALIGN="center">all</TD> <TD>non-interactive with optional output to stdout</TD> </TR> <TR> <TD><A HREF="#console">Console</A></TD> <TD ALIGN="center">all</TD> <TD>interactive console mode under user control</TD> </TR> <TR> <TD><A HREF="#curses">Curses</A></TD> <TD ALIGN="center">Linux/Unix</TD> <TD>interactive curses mode under user control</TD> </TR></TABLE></P>If these interfaces are not sufficient, clients can also usethe primitive framework API defined in<<A HREF="headers/TestRun.h">CUnit/TestRun.h</A>>. See the sourcecode for the various interfaces for examples of how to interact withthe primitive API directly.<H3 ID="automated">5.3. Automated Mode</H3>The automated interface is non-interactive. Clients initiate a test run,and the results are output to an XML file. A listing of the registered testsand suites can also be reported to an XML file.<P />The following functions comprise the automated interface API:<P ID="auto-run" CLASS="indent2"><CITE>void <B>CU_automated_run_tests</B>(void)</CITE></P><P CLASS="indent5">Runs all tests in all registered suites. Test results areoutput to a file named <I>ROOT-Results.xml</I>. The filename <I>ROOT</I> canbe set using <A HREF="#auto-setroot">CU_set_output_filename()</A>, or else the default<I>CUnitAutomated-Results.xml</I> is used. Note that if a distict filename <I>ROOT</I>is not set before each run, the results file will be overwritten.<BR /><BR />The results file is supported by both a document type definitionfile (<I>CUnit-Run.dtd</I>) and XSL stylesheet (<I>CUnit-Run.xsl</I>).These are provided in the <I>Share</I> subdirectory of the source and installationtrees.</P><P ID="auto-list" CLASS="indent2"><CITE>CU_ErrorCode <B>CU_list_tests_to_file</B>(void)</CITE></P><P CLASS="indent5">Lists the registered suites and associated tests to file.The listing file is named <I>ROOT-Listing.xml</I>. The filename <I>ROOT</I>can be set using <A HREF="#auto-setroot">CU_set_output_filename()</A>, or else the default<I>CUnitAutomated</I> is used. Note that if a distict filename <I>ROOT</I>is not set before each run, the listing file will be overwritten.<BR /><BR />The listing file is supported by both a document type definitionfile (<I>CUnit-List.dtd</I>) and XSL stylesheet (<I>CUnit-List.xsl</I>).These are provided in the <I>Share</I> subdirectory of the source and installationtrees.<BR /><BR />Note also that a listing file is not generated automatically by<A HREF="#auto-run">CU_automated_run_tests()</A>. Client code must explicitly request alisting when one is desired.</P><P ID="auto-setroot" CLASS="indent2"><CITE>void <B>CU_set_output_filename</B>(const char* szFilenameRoot)</CITE></P><P CLASS="indent5">Sets the output filenames for the results and listing files.<I>szFilenameRoot</I> is used to construct the filenames by appending<I>-Results.xml</I> and <I>-Listing.xml</I>, respectively.<H3 ID="basic">5.4. Basic Mode</H3>The basic interface is also non-interactive, with results output to stdout. Thisinterface supports running individual suites or tests, and allows client code tocontrol the type of output displayed during each run. This interface provides themost flexibility to clients desiring simplified access to the CUnit API.<P />The following public functions are provided:<P ID="basic-runall" CLASS="indent2"><CITE>CU_ErrorCode <B>CU_basic_run_tests</B>(void)</CITE></P><P CLASS="indent5">Runs all tests in all registered suites. Returns the 1sterror code occurring during the test run. The type of output is controlledby the current run mode, which can be set using <A HREF="#basic-setmode">CU_basic_set_mode()</A>.<P ID="basic-runsuite" CLASS="indent2"><CITE>CU_ErrorCode <B>CU_basic_run_suite</B>(CU_pSuite pSuite)</CITE></P><P CLASS="indent5">Runs all tests in single specified suite. Returns the 1sterror code occurring during the test run. The type of output is controlledby the current run mode, which can be set using <A HREF="#basic-setmode">CU_basic_set_mode()</A>.<P ID="basic-runtest" CLASS="indent2"><CITE>CU_ErrorCode <B>CU_basic_run_test</B>(CU_pSuite pSuite, CU_pTest pTest)</CITE></P><P CLASS="indent5">Runs a single test in a specified suite. Returns the 1sterror code occurring during the test run. The type of output is controlledby the current run mode, which can be set using <A HREF="#basic-setmode">CU_basic_set_mode()</A>.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -