📄 running_tests.html
字号:
<P ID="basic-setmode" CLASS="indent2"><CITE>void <B>CU_basic_set_mode</B>(CU_BasicRunMode mode)</CITE></P><P CLASS="indent5">Sets the basic run mode, which controls the output duringtest runs. Choices are:<P CLASS="indent10"><TABLE CELLPADDING=1> <TR> <TD><CITE>CU_BRM_NORMAL</CITE></TD> <TD>Failures and run summary are printed.</TD> </TR> <TR> <TD><CITE>CU_BRM_SILENT</CITE></TD> <TD>No output is printed except error messages.</TD> </TR> <TR> <TD><CITE>CU_BRM_VERBOSE</CITE></TD> <TD>Maximum output of run details.</TD> </TR></TABLE></P><P ID="basic-getmode" CLASS="indent2"><CITE>CU_BasicRunMode <B>CU_basic_get_mode</B>(void)</CITE></P><P CLASS="indent5">Retrieves the current basic run mode code.<P ID="basic-failure" CLASS="indent2"><CITE>void <B>CU_basic_show_failures</B>(CU_pFailureRecord pFailure)</CITE></P><P CLASS="indent5">Prints a summary of all failures to stdout.Does not depend on the run mode.<H3 ID="console">5.5. Interactive Console Mode</H3>The console interface is interactive. All the client needs to do isinitiate the console session, and the user controls the test runinteractively. This include selection & running of registered suitesand tests, and viewing test results. To start a console session, use<P ID="console-run" CLASS="indent2"><CITE>void <B>CU_console_run_tests</B>(void)</CITE></P><H3 ID="curses">5.6. Interactive Curses Mode</H3>The curses interface is interactive. All the client needs to do isinitiate the curses session, and the user controls the test runinteractively. This include selection & running of registered suites and tests, and viewing test results. Use of this interface requires linking the ncurses library into the application. To start a curses session, use<P ID="curses-run" CLASS="indent2"><CITE>void <B>CU_curses_run_tests</B>(void)</CITE></P><H3 ID="results">5.7. Getting Test Results</H3>The interfaces present results of test runs, but client code may sometimes needto access the results directly. These results include various run counts, aswell as a linked list of failure records holding the failure details. Note thattest results are overwritten each time a new test run is started, or when theregistry is <A HREF="test_registry.html#init">initialized</A> or<A HREF="test_registry.html#cleanup">cleaned up</A>.<P />Functions for accessing the test results are:<P ID="results-counts" CLASS="indent2"><CITE> unsigned int <B>CU_get_number_of_suites_run</B>(void)<BR /> unsigned int <B>CU_get_number_of_suites_failed</B>(void)<BR /> unsigned int <B>CU_get_number_of_tests_run</B>(void)<BR /> unsigned int <B>CU_get_number_of_tests_failed</B>(void)<BR /> unsigned int <B>CU_get_number_of_asserts</B>(void)<BR /> unsigned int <B>CU_get_number_of_successes</B>(void)<BR /> unsigned int <B>CU_get_number_of_failures</B>(void)</CITE></P> <P CLASS="indent5">These functions report the number of suites, tests, andassertions that ran or failed during the last run. A suite is considered failedif it's initialization or cleanup function returned non-<CODE>NULL</CODE>. A test fails if any of its assertions fail. The last 3 functions all referto individual assertions.<BR /><BR />To retrieve the total number of registered suites and tests, use<A HREF="test_registry.html#stuct">CU_get_registry()−>uiNumberOfSuites</A>and <A HREF="test_registry.html#stuct">CU_get_registry()−>uiNumberOfTests</A>,respectively.</P><P ID="results-getsummary" CLASS="indent2"><CITE>const CU_pRunSummary <B>CU_get_run_summary</B>(void)</CITE></P><P CLASS="indent5">Retrieves all test result counts at once. The return value isa pointer to a saved structure containing the counts. This data type is defined in<<A HREF="headers/TestRun.h">CUnit/TestRun.h</A>> (included automatically by<<A HREF="headers/CUnit.h">CUnit/CUnit.h</A>>):</P><PRE> 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; } <CITE><B>CU_RunSummary</B></CITE>; typedef CU_Runsummary* <CITE><B>CU_pRunSummary</B></CITE>;</PRE><P CLASS="indent5">The structure variable associated with the returned pointer is ownedby the framework, so the user should not free or otherwise change it. <I>Note that thepointer may be invalidated once another test run is initiated.</I></P><P ID="results-getfailures" CLASS="indent2"><CITE>const CU_pFailureRecord <B>CU_get_failure_list</B>(void)</CITE></P><P CLASS="indent5">Retrieves a linked list recording any failures occurring during thelast test run (<CODE>NULL</CODE> for no failures). The data type of the return valueis declared in <<A HREF="headers/TestRun.h">CUnit/TestRun.h</A>> (includedautomatically by <<A HREF="headers/CUnit.h">CUnit/CUnit.h</A>>). Each failurerecord contains information about the location and nature of the failure:</P><PRE> 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; } <CITE><B>CU_FailureRecord</B></CITE>; typedef CU_FailureRecord* <CITE><B>CU_pFailureRecord</B></CITE>;</PRE><P CLASS="indent5">The structure variable associated with the returned pointer is ownedby the framework, so the user should not free or otherwise change it. <I>Note that thepointer may be invalidated once another test run is initiated.</I></P><P ID="results-failurecount" CLASS="indent2"><CITE> unsigned int <B>CU_get_number_of_failure_records</B>(void)<BR /></CITE></P><P CLASS="indent5">Retrieves the number of <CITE>CU_FailureRecords</CITE> inthe linked list of failures returned by <CITE>CU_get_failure_list()</CITE>. Notethat this can be more than the number of failed assertions, since suiteinitialization and cleanup failures are included.</P><H3 ID="deprecated">5.8. Deprecated v1 Data Types & Functions</H3>The following data types and functions are deprecated as of version 2.To use these deprecated names, user code must be compiled with<CITE>USE_DEPRECATED_CUNIT_NAMES</CITE> defined.<P /><TABLE CELLPADDING=5 BORDER=2> <TR VALIGN="top"> <TD><B>Deprecated Name</B></TD> <TD><B>Equivalent New Name</B></TD> </TR> <TR VALIGN="top"> <TD><CODE>automated_run_tests()</CODE></TD> <TD> <A HREF="#auto-run">CU_automated_run_tests()</A> plus<BR /> <A HREF="#auto-list">CU_list_tests_to_file()</A> </TD> </TR> <TR VALIGN="top"> <TD><CODE>set_output_filename()</CODE></TD> <TD><A HREF="#auto-setroot">CU_set_output_filename()</A></TD> </TR> <TR VALIGN="top"> <TD><CODE>console_run_tests()</CODE></TD> <TD><A HREF="#console-run">CU_console_run_tests()</A></TD> </TR> <TR VALIGN="top"> <TD><CODE>curses_run_tests()</CODE></TD> <TD><A HREF="#curses-run">CU_curses_run_tests()</A></TD> </TR></TABLE><DIV CLASS="NAVFOOTER"><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0"> <TR> <TD WIDTH="33%" ALIGN="left" VALIGN="top"><A HREF="managing_tests.html" ACCESSKEY="P">Prev</A></TD> <TD WIDTH="34%" ALIGN="center" VALIGN="top"><A HREF="index.html" ACCESSKEY="H" >Home</A></TD> <TD WIDTH="33%" ALIGN="right" VALIGN="top"><A HREF="error_handling.html" ACCESSKEY="N" >Next</A></TD> </TR> <TR> <TD WIDTH="33%" ALIGN="left" VALIGN="top">Managing Tests & Suites</TD> <TD WIDTH="34%" ALIGN="center" VALIGN="top"> </TD> <TD WIDTH="33%" ALIGN="right" VALIGN="top">Error Handling</TD> </TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -