Gtest recommended two documents:
http://www.ibm.com/developerworks/cn/linux/l-cn-cppunittest/
And
Http://www.cnblogs.com/coderzh/archive/2009/04/06/1426755.html
When using Gtest for C + + unit testing, it is often necessary to encapsulate the XML report generated by Gtest, but the testcase element gtest The default output has the following properties:
<testcase name= "One" status= "Run" time= "1.355" classname= "Hello"/>
Where the name value cannot be in Chinese, classname is the class name of this testcase, and cannot contain too much information, to generate a detailed report, you must add a new attribute value to the testcase element.
View Gtest source code, UnitTest class actually has a method: Recordproperty, can add a custom attribute for XML, usage:
Test_f (Hello, one) {
this->recordproperty ("desc", "abc");
}
Of course, for more convenience, it is recommended to define this as a macro:
#define CASE_DESC (DESC) this->recordproperty ("desc", desc);
Test_f (Hello, one) {
Case_desc ("abc");
}
This will have one more attribute in the XML report generated by Gtest. Desc
<testcase name= "One" status= "Run" time= "1.355" classname= "Hello" desc= "abc"/>
But here if you want to add Chinese in desc will not be displayed in XML (directly filtered out),
Look at the gtest.cc, make the following changes in the code to:
M << ch;
/* Remove the comment below and change it to the above sentence to solve the problem of Chinese filtering ^ ^
if (Isvalidxmlcharacter (ch)) {
if (Is_attribute && Isnormalizablewhitespace (CH))
m << "& #x" << string::formatbyte (static_cast<unsigned char> (CH))
<< ";";
else
m << ch;
} */