📄 x232.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><HTML><HEAD><TITLE>Test Logging </TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINKREL="HOME"TITLE="Check Tutorial"HREF="index.html"><LINKREL="UP"TITLE="Advanced Features "HREF="c163.html"><LINKREL="PREVIOUS"TITLE="Test timeouts "HREF="x226.html"><LINKREL="NEXT"TITLE="Conclusion "HREF="x246.html"></HEAD><BODYCLASS="SECTION"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">Check Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="x226.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 4. Advanced Features</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="x246.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECTION"><H1CLASS="SECTION"><ANAME="AEN232">4.7. Test Logging<ANAME="TESTLOGGING"></A></A></H1><P>Check supports operation to log the results of a test run. To use test logging, use the srunner_set_log function with the name of the log file you wish to create: </P><PRECLASS="PROGRAMLISTING">SRunner *sr;sr = srunner_create(make_s1_suite());srunner_add_suite(sr, make_s2_suite());srunner_set_log(sr, "test.log");srunner_run_all(sr, CRNORMAL);</PRE><P>Check will write the results of the run to test.log. The printmode argument to srunner_run_all does not apply to test logging; the log will contain a result entry, organized by suite, for every test run. Here is an example of test log output: </P><PRECLASS="PROGRAMLISTING">Running suite S1 ex_log_output.c:8:P:Core:test_pass: Test passedex_log_output.c:14:F:Core:test_fail: Failureex_log_output.c:18:E:Core:test_exit: (after this point) Early exit with return value 1Running suite S2 ex_log_output.c:26:P:Core:test_pass2: Test passedResults for all suites run:50%: Checks: 4, Failures: 1, Errors: 1</PRE><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="AEN239">4.7.1. XML logging</A></H2><P>The log can also be written in XML. The following functions define the interface for XML logs: </P><PRECLASS="PROGRAMLISTING">void srunner_set_xml(SRunner *sr, const char *fname);int srunner_has_xml(SRunner *sr);const char *srunner_xml_fname(SRunner *sr);</PRE><P>The only thing you need to do to get XML output is call <CODECLASS="FUNCTION">srunner_set_xml()</CODE> before the tests are run. Here is an example of the same log output as above but in XML: </P><PRECLASS="PROGRAMLISTING"><?xml version="1.0"?><testsuites xmlns="http://check.sourceforge.net/ns"> <datetime>2004-08-20 12:53:32</datetime> <suite> <title>S1</title> <test result="success"> <path>.</path> <fn>ex_xml_output.c:8</fn> <id>test_pass</id> <description>Core</description> <message>Passed</message> </test> <test result="failure"> <path>.</path> <fn>ex_xml_output.c:14</fn> <id>test_fail</id> <description>Core</description> <message>Failure</message> </test> <test result="error"> <path>.</path> <fn>ex_xml_output.c:18</fn> <id>test_exit</id> <description>Core</description> <message>Early exit with return value 1</message> </test> </suite> <suite> <title>S2</title> <test result="success"> <path>.</path> <fn>ex_xml_output.c:26</fn> <id>test_pass2</id> <description>Core</description> <message>Passed</message> </test> </suite> <duration>0.304875</duration></testsuites></PRE></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="x226.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="index.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="x246.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Test timeouts</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="c163.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Conclusion</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -