I am using Google Test to generate an XML Report. I am also using pandoc to write my reports.
Is it possible to use pandoc to convert the XML Google Test report into an HTML file where the XML elements are represented in nice tables automagically?
Here is the example of the XML report of a failing test:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="8" failures="1" disabled="0" errors="0" timestamp="2015-05-29T11:40:56" time="0.018" name="AllTests">
<testsuite name="orientPoints" tests="8" failures="1" disabled="0" errors="0" time="0.018">
<testcase name="trianglePolygon" status="run" time="0" classname="orientPoints" />
<testcase name="regularOctogon" status="run" time="0" classname="orientPoints" />
<testcase name="orientRegularOctogon" status="run" time="0" classname="orientPoints" />
<testcase name="square" status="run" time="0" classname="orientPoints" />
<testcase name="rectangleDuplicateEdges" status="run" time="0" classname="orientPoints" />
<testcase name="orientationBug" status="run" time="0" classname="orientPoints" />
<testcase name="randomCirclePointsOrientedByProjection" status="run" time="0.018" classname="orientPoints" />
<testcase name="uniqueSquareWithDuplicatePoints" status="run" time="0" classname="orientPoints">
<failure message="geomTestOrient.C:425
Value of: pointChainIsOriented( squareOriented.begin(), squareOriented.end(), squareNormal )
Actual: false
Expected: true" type=""><![CDATA[geomTestOrient.C:425
Value of: pointChainIsOriented( squareOriented.begin(), squareOriented.end(), squareNormal )
Actual: false
Expected: true]]></failure>
<failure message="geomTestOrient.C:443
Value of: squareOriented.size() == 4
Actual: false
Expected: true
failed iteration : 0
square size : 14
oriented unique square size : 6
input front : (-5.9729471176018073e-16 1.0000000000000007 6.1131855418087139e-16)
input back : (1.0000000000000004 0.99999999999999933 5.2878054241263088e-16)
" type=""><![CDATA[geomTestOrient.C:443
Value of: squareOriented.size() == 4
Actual: false
Expected: true
failed iteration : 0
square size : 14
oriented unique square size : 6
input front : (-5.9729471176018073e-16 1.0000000000000007 6.1131855418087139e-16)
input back : (1.0000000000000004 0.99999999999999933 5.2878054241263088e-16)
]]></failure>
</testcase>
</testsuite>
</testsuites>
Related
I have duplicate entry in my xml column in my sql table see material8 key.I remove one entry.I am trying below query its removing both.Is there any way i can remove only one entry.
Update mytable set xml = replace (xml, "<Book key=\"material8\" active=\"true\" displayOrder=\"5\" />", "") where id = 9 and type_key="mykey1";
<?xml version="1.0" encoding="UTF-8"?>
<Type key="test1" publicKey="test2" >
<UIProperties>
<label locale="en_US">My book</label>
</UIProperties>
<Books>
<Book key="material1" active="true" displayOrder="0" >
<UIProperties>
<label locale="en_US">My Books</label>
</UIProperties>
</Book>
<Book key="material2" />
<Book key="material3" active="true" displayOrder="3" >
<Pages>
<Page key="material4" active="true" displayOrder="0" />
<Page key="material5" active="true" displayOrder="1" />
</Pages>
</Book>
<Book key="material6" active="true" displayOrder="4" />
<Book key="material7" active="true" displayOrder="2" />
<Book key="material8" active="true" displayOrder="5" />
<Book key="material8" active="true" displayOrder="5" />
</Books>
<Attributes>
<Attribute key="desc" />
<Attribute key="date1" />
<Attribute key="date2" />
</Attributes>
</Type>
A simple solution is to replace 2 books to 1, instead of 1 to none:
UPDATE mytable
SET xml = REPLACE(xml, "<Book key=\"material8\" active=\"true\" displayOrder=\"5\" /><Book key=\"material8\" active=\"true\" displayOrder=\"5\" />", "<Book key=\"material8\" active=\"true\" displayOrder=\"5\" />")
WHERE id = 9
AND type_key="mykey1";
I need to use Multi Reporters for Mocha, so I choose:
https://github.com/stanleyhlng/mocha-multi-reporters
Everything is ok, but I need use custom reporter - mocha-junit-reporter .
How can I use in mocha-multi-reporters mocha-junit-reporter ?
I've tried something like this:
"junitReporterOptions": {
"id": "junit",
"reporter": "mocha-junit-reporter",
"output": "../../cms2/raportUnitTestsjunit.xml"
},
But I've got "Reporter does not found! junit" . Is it compatible with mocha-multi-reporters ?
You can install "mocha-multi-reporters#1.1.1" to use "mocha-junit-reporter" custom reporter.
// File: config.json
{
"reporterEnabled": "mocha-junit-reporter",
"mochaJunitReporterReporterOptions": {
"mochaFile": "junit-custom.xml"
}
}
$ ./node_modules/.bin/mocha --reporter mocha-multi-reporters --reporter-options configFile=config.json
1..4
ok 1 mocha-test 1 sample test 1.1
ok 2 mocha-test 1 sample test 1.2
ok 3 mocha-test 2 sample test 2.1
ok 4 mocha-test 2 sample test 2.2 # SKIP -
# tests 3
# pass 3
# fail 0
$ cat xunit-custom.xml
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="Mocha Tests" time="0.001" tests="4" failures="0" skipped="1">
<testsuite name="Root Suite" timestamp="2016-10-30T02:27:54" tests="0" failures="0" time="0">
</testsuite>
<testsuite name="mocha-test #1" timestamp="2016-10-30T02:27:54" tests="2" failures="0" time="0.001">
<testcase name="mocha-test #1 sample test #1.1" time="0.001" classname="sample test #1.1">
</testcase>
<testcase name="mocha-test #1 sample test #1.2" time="0" classname="sample test #1.2">
</testcase>
</testsuite>
<testsuite name="mocha-test #2" timestamp="2016-10-30T02:27:54" tests="2" failures="0" time="0">
<testcase name="mocha-test #2 sample test #2.1" time="0" classname="sample test #2.1">
</testcase>
</testsuite>
</testsuites>
You can find a demo project # https://github.com/stanleyhlng/mocha-multi-reporters-demo
Hope this help!
I just used qunit-reporter-junit to generate the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="http://w188823.example.com:9001/test/workflow.cloning?out=xml" hostname="localhost" tests="19" failures="2" errors="0" time="0.357" timestamp="2013-07-16T19:52:00Z">
<testsuite id="0" name="workflow.cloning.test" hostname="localhost" tests="4" failures="0" errors="0" time="0.002" timestamp="2013-07-16T19:52:00Z">
<testcase name="has schedule departure date predicate" tests="4" failures="0" errors="0" time="0.002" timestamp="2013-07-16T19:52:00Z">
</testcase>
</testsuite>
<testsuite id="1" name="workflow.cloning.test" hostname="localhost" tests="8" failures="0" errors="0" time="0.001" timestamp="2013-07-16T19:52:00Z">
<testcase name="has effective date predicate" tests="4" failures="0" errors="0" time="0.001" timestamp="2013-07-16T19:52:00Z">
</testcase>
</testsuite>
<testsuite id="2" name="workflow.cloning.test" hostname="localhost" tests="12" failures="0" errors="0" time="0.001" timestamp="2013-07-16T19:52:00Z">
<testcase name="has origin and destination predicate" tests="4" failures="0" errors="0" time="0.001" timestamp="2013-07-16T19:52:00Z">
</testcase>
</testsuite>
<testsuite id="3" name="workflow.cloning.test" hostname="localhost" tests="13" failures="1" errors="0" time="0" timestamp="2013-07-16T19:52:00Z">
<testcase name="has AFE detour number predicate" tests="1" failures="1" errors="0" time="0" timestamp="2013-07-16T19:52:00Z">
<failure type="AssertionFailedError" message="Died on test #1: 'undefined' is not an object (evaluating 'data.cloneParams.fromCategory')" />
</testcase>
<system-out>
<![CDATA[
[workflow.cloning.test, has AFE detour number predicate, 1] Died on test #1: 'undefined' is not an object (evaluating 'data.cloneParams.fromCategory')
]]>
</system-out>
</testsuite>
<testsuite id="4" name="workflow.cloning.test" hostname="localhost" tests="14" failures="2" errors="0" time="0" timestamp="2013-07-16T19:52:00Z">
<testcase name="has scenarios predicate" tests="1" failures="1" errors="0" time="0" timestamp="2013-07-16T19:52:00Z">
<failure type="AssertionFailedError" message="Died on test #1: 'undefined' is not an object (evaluating 'data.cloneParams.fromCategory')" />
</testcase>
<system-out>
<![CDATA[
[workflow.cloning.test, has scenarios predicate, 1] Died on test #1: 'undefined' is not an object (evaluating 'data.cloneParams.fromCategory')
]]>
</system-out>
</testsuite>
<testsuite id="5" name="workflow.cloning.test" hostname="localhost" tests="19" failures="2" errors="0" time="0.001" timestamp="2013-07-16T19:52:00Z">
<testcase name="clone warning in comments predicate" tests="5" failures="0" errors="0" time="0.001" timestamp="2013-07-16T19:52:00Z">
</testcase>
</testsuite>
</testsuites>
But when I run it, and the xsd I found at: https://svn.jenkins-ci.org/trunk/hudson/dtkit/dtkit-format/dtkit-junit-model/src/main/resources/com/thalesgroup/dtkit/junit/model/xsd/junit-4.xsd (which is appropriate as we are using Jenkins), through the validator at this site: http://www.freeformatter.com/xml-validator-xsd.html
It reports the errors below. So is qunit-reporter-junit really generating compliant xml? Are there other ways I could be validating this?
Cvc-complex-type.3.2.2: Attribute 'hostname' Is Not Allowed To Appear In Element 'testsuites'.. Line '2', Column '181'.
Cvc-complex-type.3.2.2: Attribute 'timestamp' Is Not Allowed To Appear In Element 'testsuites'.. Line '2', Column '181'.
Cvc-complex-type.3.2.2: Attribute 'tests' Is Not Allowed To Appear In Element 'testcase'.. Line '4', Column '136'.
Cvc-complex-type.3.2.2: Attribute 'failures' Is Not Allowed To Appear In Element 'testcase'.. Line '4', Column '136'.
Cvc-complex-type.3.2.2: Attribute 'errors' Is Not Allowed To Appear In Element 'testcase'.. Line '4', Column '136'.
Cvc-complex-type.3.2.2: Attribute 'timestamp' Is Not Allowed To Appear In Element 'testcase'.. Line '4', Column '136'.
Cvc-complex-type.3.2.2: Attribute 'tests' Is Not Allowed To Appear In Element 'testcase'.. Line '8', Column '127'.
Cvc-complex-type.3.2.2: Attribute 'failures' Is Not Allowed To Appear In Element 'testcase'.. Line '8', Column '127'.
Cvc-complex-type.3.2.2: Attribute 'errors' Is Not Allowed To Appear In Element 'testcase'.. Line '8', Column '127'.
Cvc-complex-type.3.2.2: Attribute 'timestamp' Is Not Allowed To Appear In Element 'testcase'.. Line '8', Column '127'.
Cvc-complex-type.3.2.2: Attribute 'tests' Is Not Allowed To Appear In Element 'testcase'.. Line '12', Column '135'.
Cvc-complex-type.3.2.2: Attribute 'failures' Is Not Allowed To Appear In Element 'testcase'.. Line '12', Column '135'.
Cvc-complex-type.3.2.2: Attribute 'errors' Is Not Allowed To Appear In Element 'testcase'.. Line '12', Column '135'.
Cvc-complex-type.3.2.2: Attribute 'timestamp' Is Not Allowed To Appear In Element 'testcase'.. Line '12', Column '135'.
Cvc-complex-type.3.2.2: Attribute 'tests' Is Not Allowed To Appear In Element 'testcase'.. Line '16', Column '126'.
Cvc-complex-type.3.2.2: Attribute 'failures' Is Not Allowed To Appear In Element 'testcase'.. Line '16', Column '126'.
Cvc-complex-type.3.2.2: Attribute 'errors' Is Not Allowed To Appear In Element 'testcase'.. Line '16', Column '126'.
Cvc-complex-type.3.2.2: Attribute 'timestamp' Is Not Allowed To Appear In Element 'testcase'.. Line '16', Column '126'.
Cvc-complex-type.3.2.2: Attribute 'tests' Is Not Allowed To Appear In Element 'testcase'.. Line '26', Column '118'.
Cvc-complex-type.3.2.2: Attribute 'failures' Is Not Allowed To Appear In Element 'testcase'.. Line '26', Column '118'.
Cvc-complex-type.3.2.2: Attribute 'errors' Is Not Allowed To Appear In Element 'testcase'.. Line '26', Column '118'.
Cvc-complex-type.3.2.2: Attribute 'timestamp' Is Not Allowed To Appear In Element 'testcase'.. Line '26', Column '118'.
Cvc-complex-type.3.2.2: Attribute 'tests' Is Not Allowed To Appear In Element 'testcase'.. Line '36', Column '134'.
Cvc-complex-type.3.2.2: Attribute 'failures' Is Not Allowed To Appear In Element 'testcase'.. Line '36', Column '134'.
Cvc-complex-type.3.2.2: Attribute 'errors' Is Not Allowed To Appear In Element 'testcase'.. Line '36', Column '134'.
Cvc-complex-type.3.2.2: Attribute 'timestamp' Is Not Allowed To Appear In Element 'testcase'.. Line '36', Column '134'.
Take a look at this discussion at GitHub please. The issue is already closed - maybe it depends on the product version.
I'm trying to parse an xml file output from googletest to display the results in a pretty way in an html page. I have had a fair crack at it and have a working solution. Only one thing left to do.
Currently each class has a header and each function+test is displayed underneath, I'm looking for a way to extract the function name from the xml attribute to have it as its own sub-heading. Example below
Current Output
Class Name
functionName_testName
functionName_test2Name
function2Name_testName
Desired Output
Class Name
functionName
testName
test2Name
function2Name
testName
XML To be Parsed
<testsuite name="testPacketProcessor" tests="27" failures="0" disabled="0" errors="0" time="36.875">
<testcase name="testInitialise_IpNotSet" status="run" time="0" classname="testPacketProcessor" />
<testcase name="testInitialise_GoodIp" status="run" time="2.046" classname="testPacketProcessor" />
<testcase name="testInitialise_BadIp" status="run" time="0.032" classname="testPacketProcessor" />
</testsuite>
XSL Currently Implemented
<xsl:for-each select="testsuites/testsuite">
<div class="testHeading">
<span><xsl:value-of select="substring-after(#name,'test')"/></span>
</div>
<xsl:for-each select="testcase">
<div class="testReport">
<xsl:if test="not(starts-with(#name,'DISABLED'))"><xsl:value-of select="substring-after(#name,'test')"/></xsl:if>
<xsl:if test="starts-with(#name,'DISABLED')"><xsl:value-of select="substring-after(#name,'DISABLED_test')"/></xsl:if>
<xsl:text> - </xsl:text>
<xsl:if test="starts-with(#status,'run')">
<xsl:if test="failure"><xsl:text>Fail</xsl:text></xsl:if>
<xsl:if test= "not(failure)"><xsl:text>Pass</xsl:text></xsl:if>
</xsl:if>
<xsl:if test="starts-with(#status,'not')"><xsl:text>Disabled</xsl:text></xsl:if>
</div>
</xsl:for-each>
</xsl:for-each>
Using the above xml as an example I would like a subheading of "Initialise" under the packet processor heading with each test doucumented under the subheading
Any advice on the best way to go about this would be much appreciated. I've looked at xsl variables but cannot fathom how to deal with not being able to change the value. Have also read a little on xsl templates and recursion but I'm not sure how that would work for this situation.
Thanks in advance
Dougie
This transformation produces the subheading and name for each testcase:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="testcase">
Subheading: <xsl:value-of select=
"substring-before(substring-after(#name, 'test'),
'_'
)
"/>
Name: <xsl:value-of select="substring-after(#name, '_')"/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
When applied on the provided XML document:
<testsuites>
<testsuite name="testPacketProcessor" tests="27" failures="0" disabled="0" errors="0" time="36.875">
<testcase name="testInitialise_IpNotSet" status="run" time="0" classname="testPacketProcessor" />
<testcase name="testInitialise_GoodIp" status="run" time="2.046" classname="testPacketProcessor" />
<testcase name="testInitialise_BadIp" status="run" time="0.032" classname="testPacketProcessor" />
</testsuite>
</testsuites>
the wanted, correct result is produced:
Subheading: Initialise
Name: IpNotSet
Subheading: Initialise
Name: GoodIp
Subheading: Initialise
Name: BadIp
Explanation: Using the standard XPath functions substring-before() and substring-after()
Edit: In a comment the OP clarified that he wanted grouping by function (tired of bad questions ?):
This transformation performs the wanted grouping:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="kTestsByFunction" match="testcase"
use="substring-before(substring-after(#name, 'test'),
'_'
)"
/>
<xsl:template match=
"testcase
[generate-id()
=
generate-id(key('kTestsByFunction',
substring-before(substring-after(#name, 'test'),
'_'
)
)[1]
)
]
">
Subheading:
<xsl:value-of select=
"substring-before(substring-after(#name, 'test'),
'_'
)
"/>
<xsl:for-each select=
"key('kTestsByFunction',
substring-before(substring-after(#name, 'test'),
'_'
)
)
">
Name:
<xsl:value-of select="substring-after(#name, '_')"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
and produces the wanted result:
Subheading:
Initialise
Name:
IpNotSet
Name:
GoodIp
Name:
BadIp
I've got what seems like a very simple example of an xsd and xml file where the xml file does not validate.
Copies of the two files are below.
The first xml element with id = 'fixMe' gets an error that says
Top level is not completed.
Valid xml document must have a root tag
If I remove its id attribute or use "idx" instead of "id", it's fine. But I can't figure out why. 'id' should be a valid attribute.
Any insight appreciated.
XML:
<question id="fixMe" />
<question idx="ok"/>
<question />
XSD:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="perceptive.com/mi/analysis"
xmlns="perceptive.com/mi/analysis"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="test" type="test"/>
<xs:complexType name="test">
<xs:sequence minOccurs="1" maxOccurs="10">
<xs:element name="question" type="question_type"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="question_type">
<xs:attribute name="idx" type="xs:string" use="optional"/>
<xs:attribute name="id" type="xs:string" use="optional"/>
</xs:complexType>
</xs:schema>
An XML document cannot be valid until it is well-formed.
So you should specify a root tag in XML document, e.g.:
<root>
<question id="fixMe" />
<question idx="ok"/>
<question />
</root>