From c7afbb5844361ffa112e4946abb1772a3da19144 Mon Sep 17 00:00:00 2001 From: David Linse Date: Fri, 4 Jul 2014 13:32:17 +0200 Subject: [PATCH] Read optional 'name' property from failure This allows to pass in a custom name which is used in the junit xml report. --- docs/modules/tester.rst | 3 ++- docs/testing.rst | 21 +++++++++++++++++++++ modules/xunit.js | 2 +- tests/suites/xunit.js | 22 ++++++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/docs/modules/tester.rst b/docs/modules/tester.rst index 1e61843e5..72ac4ec59 100644 --- a/docs/modules/tester.rst +++ b/docs/modules/tester.rst @@ -721,11 +721,12 @@ Writes an error-style formatted message to stdout:: ``fail()`` ------------------------------------------------------------------------------- -**Signature:** ``fail(String message)`` +**Signature:** ``fail(String message [, Object option])`` Adds a failed test entry to the stack:: casper.test.fail("Georges W. Bush"); + casper.test.fail("Here goes a really long and expressive message", {name:'shortfacts'}); .. seealso:: `pass()`_ diff --git a/docs/testing.rst b/docs/testing.rst index d0c9bdc1c..bf9d18314 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -246,6 +246,27 @@ You should get a pretty XUnit XML report like this: +You can customize the value for the `name` property by passing an object to `casper.test.fail()` like: + +.. code-block:: js + + casper.test.fail('google search for "casperjs" retrieves 10 or more results', {name: 'result count is 10+'}); + +.. code-block:: xml + + + + + + + + + + google search for "casperjs" retrieves 10 or more results + + + + CasperJS own tests ------------------ diff --git a/modules/xunit.js b/modules/xunit.js index 9205c1909..a19d460c1 100644 --- a/modules/xunit.js +++ b/modules/xunit.js @@ -117,7 +117,7 @@ XUnitExporter.prototype.getXML = function getXML() { // failed test cases result.failures.forEach(function(failure) { var testCase = utils.node('testcase', { - name: failure.message || failure.standard, + name: failure.name || failure.message || failure.standard, classname: generateClassName(failure.file), time: utils.ms2seconds(~~failure.time) }); diff --git a/tests/suites/xunit.js b/tests/suites/xunit.js index 689285edd..5dd15c531 100644 --- a/tests/suites/xunit.js +++ b/tests/suites/xunit.js @@ -75,3 +75,25 @@ casper.test.begin('XUnitReporter() can handle a failed test', 2, function suite( test.assertEquals(casper.getElementInfo('failure[type="footype"]').text, 'footext'); test.done(); }); + +casper.test.begin('XUnitReporter() can handle custom name attribute for a test case', 2, function suite(test) { + var xunit = require('xunit').create(); + var results = new tester.TestSuiteResult(); + var suite1 = new tester.TestCaseResult({ + name: 'foo', + file: '/foo' + }); + suite1.addFailure({ + success: false, + type: "footype", + message: "footext", + file: "/foo", + name: "foo bar baz" + }); + results.push(suite1); + xunit.setResults(results); + casper.start().setContent(xunit.getSerializedXML()); + test.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="foo bar baz"] failure[type="footype"]'); + test.assertEquals(casper.getElementInfo('failure[type="footype"]').text, 'footext'); + test.done(); +});