Commit c7afbb58 c7afbb5844361ffa112e4946abb1772a3da19144 by David Linse Committed by David Linse

Read optional 'name' property from failure

This allows to pass in a custom name which is used
in the junit xml report.
1 parent 44d0d7b5
...@@ -721,11 +721,12 @@ Writes an error-style formatted message to stdout:: ...@@ -721,11 +721,12 @@ Writes an error-style formatted message to stdout::
721 ``fail()`` 721 ``fail()``
722 ------------------------------------------------------------------------------- 722 -------------------------------------------------------------------------------
723 723
724 **Signature:** ``fail(String message)`` 724 **Signature:** ``fail(String message [, Object option])``
725 725
726 Adds a failed test entry to the stack:: 726 Adds a failed test entry to the stack::
727 727
728 casper.test.fail("Georges W. Bush"); 728 casper.test.fail("Georges W. Bush");
729 casper.test.fail("Here goes a really long and expressive message", {name:'shortfacts'});
729 730
730 .. seealso:: `pass()`_ 731 .. seealso:: `pass()`_
731 732
......
...@@ -246,6 +246,27 @@ You should get a pretty XUnit XML report like this: ...@@ -246,6 +246,27 @@ You should get a pretty XUnit XML report like this:
246 </testsuite> 246 </testsuite>
247 </testsuites> 247 </testsuites>
248 248
249 You can customize the value for the `name` property by passing an object to `casper.test.fail()` like:
250
251 .. code-block:: js
252
253 casper.test.fail('google search for "casperjs" retrieves 10 or more results', {name: 'result count is 10+'});
254
255 .. code-block:: xml
256
257 <?xml version="1.0" encoding="UTF-8"?>
258 <testsuites duration="1.249">
259 <testsuite errors="0" failures="0" name="Google search retrieves 10 or more results" package="googletesting" tests="5" time="1.249" timestamp="2012-12-30T21:27:26.320Z">
260 <testcase classname="googletesting" name="google homepage title is the one expected" time="0.813"/>
261 <testcase classname="googletesting" name="main form is found" time="0.002"/>
262 <testcase classname="googletesting" name="google title is ok" time="0.416"/>
263 <testcase classname="googletesting" name="search term has been submitted" time="0.017"/>
264 <testcase classname="googletesting" name="results count is 10+" time="0.001"/>
265 <failure type="fail">google search for "casperjs" retrieves 10 or more results</failure>
266 <system-out/>
267 </testsuite>
268 </testsuites>
269
249 CasperJS own tests 270 CasperJS own tests
250 ------------------ 271 ------------------
251 272
......
...@@ -117,7 +117,7 @@ XUnitExporter.prototype.getXML = function getXML() { ...@@ -117,7 +117,7 @@ XUnitExporter.prototype.getXML = function getXML() {
117 // failed test cases 117 // failed test cases
118 result.failures.forEach(function(failure) { 118 result.failures.forEach(function(failure) {
119 var testCase = utils.node('testcase', { 119 var testCase = utils.node('testcase', {
120 name: failure.message || failure.standard, 120 name: failure.name || failure.message || failure.standard,
121 classname: generateClassName(failure.file), 121 classname: generateClassName(failure.file),
122 time: utils.ms2seconds(~~failure.time) 122 time: utils.ms2seconds(~~failure.time)
123 }); 123 });
......
...@@ -75,3 +75,25 @@ casper.test.begin('XUnitReporter() can handle a failed test', 2, function suite( ...@@ -75,3 +75,25 @@ casper.test.begin('XUnitReporter() can handle a failed test', 2, function suite(
75 test.assertEquals(casper.getElementInfo('failure[type="footype"]').text, 'footext'); 75 test.assertEquals(casper.getElementInfo('failure[type="footype"]').text, 'footext');
76 test.done(); 76 test.done();
77 }); 77 });
78
79 casper.test.begin('XUnitReporter() can handle custom name attribute for a test case', 2, function suite(test) {
80 var xunit = require('xunit').create();
81 var results = new tester.TestSuiteResult();
82 var suite1 = new tester.TestCaseResult({
83 name: 'foo',
84 file: '/foo'
85 });
86 suite1.addFailure({
87 success: false,
88 type: "footype",
89 message: "footext",
90 file: "/foo",
91 name: "foo bar baz"
92 });
93 results.push(suite1);
94 xunit.setResults(results);
95 casper.start().setContent(xunit.getSerializedXML());
96 test.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="foo bar baz"] failure[type="footype"]');
97 test.assertEquals(casper.getElementInfo('failure[type="footype"]').text, 'footext');
98 test.done();
99 });
......