Test Logging

Check Tutorial
Prev | Chapter 4. Advanced Features | Next

# 4.7. Test Logging

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:

    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);

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:

    Running suite S1
    ex_log_output.c:8:P:Core:test_pass: Test passed
    ex_log_output.c:14:F:Core:test_fail: Failure
    ex_log_output.c:18:E:Core:test_exit: (after this point) Early exit with return value 1
    Running suite S2
    ex_log_output.c:26:P:Core:test_pass2: Test passed
    Results for all suites run:
    50%: Checks: 4, Failures: 1, Errors: 1

## 4.7.1. XML logging

The log can also be written in XML. The following functions define the interface for XML logs:

    void srunner_set_xml(SRunner *sr, const char *fname);
    int srunner_has_xml(SRunner *sr);
    const char *srunner_xml_fname(SRunner *sr);

The only thing you need to do to get XML output is call `srunner_set_xml()` before the tests are run. Here is an example of the same log output as above but in XML:

    <?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>

Prev | Home | Next
Test timeouts | Up | Conclusion