How to add custom properties for Gtest XML reports

Source: Internet
Author: User

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;
        } */



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.