高效工作、快乐生活

gtest for xml output

上一篇 / 下一篇  2010-05-17 14:42:39 / 个人分类:googel test

Google Test can emit a detailed XML report to a file in addition to its normal textual output. The report contains the duration of each test, and thus can help you identify slow tests.

To generate the XML report, set the GTEST_OUTPUT environment variable or the --gtest_output flag to the string "xml:_path_to_output_file_", which will create the file at the given location. You can also just use the string "xml", in which case the output can be found in the test_detail.xml file in the current directory.

If you specify a directory (for example, "xml:output/directory/" on Linux or "xml:output\directory\" on Windows), Google Test will create the XML file in that directory, named after the test executable (e.g. foo_test.xml for test program foo_test or foo_test.exe). If the file already exists (perhaps left over from a previous run), Google Test will pick a different name (e.g. foo_test_1.xml) to avoid overwriting it.

The report uses the format described here. It is based on the junitreport Ant task and can be parsed by popular continuous build systems like Hudson. Since that format was originally intended for Java, a little interpretation is required to make it apply to Google Test tests, as shown here:


<testsuites
name="AllTests"...>
<testsuitename="test_case_name"...>
<testcasename="test_name"...>
<failuremessage="..."/>
<failuremessage="..."/>
<failuremessage="..."/>
</testcase>
</testsuite>
</testsuites>
  • The root<testsuites>element corresponds to the entire test program.
  • <testsuite>elements correspond to Google Test test cases.
  • <testcase>elements correspond to Google Test test functions.

For instance, the following program

TEST(MathTest,Addition){...}
TEST
(MathTest,Subtraction){...}
TEST
(LogicTest,NonContradiction){...}

could generate this report:

<?xml version="1.0"encoding="UTF-8"?>
<testsuitestests="3"failures="1"errors="0"time="35"name="AllTests">
<testsuitename="MathTest"tests="2"failures="1"*errors="0"time="15">
<testcasename="Addition"status="run"time="7"classname="">
<failuremessage="Value of: add(1, 1)&#x0A; Actual: 3&#x0A;Expected: 2"type=""/>
<failuremessage="Value of: add(1, -1)&#x0A; Actual: 1&#x0A;Expected: 0"type=""/>
</testcase>
<testcasename="Subtraction"status="run"time="5"classname="">
</testcase>
</testsuite>
<testsuitename="LogicTest"tests="1"failures="0"errors="0"time="5">
<testcasename="NonContradiction"status="run"time="5"classname="">
</testcase>
</testsuite>
</testsuites>

Things to note:

  • Thetestsattribute of a<testsuites>or<testsuite>element tells how many test functions the Google Test program or test case contains, while thefailuresattribute tells how many of them failed.
  • Thetimeattribute expresses the duration of the test, test case, or entire test program in milliseconds.
  • Each<failure>element corresponds to a single failed Google Test assertion.
  • Some JUnit concepts don't apply to Google Test, yet we have to conform. to the DTD. Therefore you'll see some dummy elements and attributes in the report. You can safely ignore these parts.

Availability:Linux, Windows, Mac.

本文为转载,版权归原作者所有


TAG:

 

评分:0

我来说两句

xavier_007

xavier_007

目前从事gis行业导航相关测试; 熟悉语言c/cpp/vbs/lua/java 熟悉工具gtest/autoit/qtp/lr 良好英语和思维能力

日历

« 2024-05-08  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 11356
  • 日志数: 18
  • 建立时间: 2008-11-26
  • 更新时间: 2012-11-21

RSS订阅

Open Toolbar