8000 refs #966 - read optional 'name' property from failure by davidlinse · Pull Request #967 · casperjs/casperjs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jun 19, 2020. It is now read-only.

refs #966 - read optional 'name' property from failure #967

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/modules/tester.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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()`_

Expand Down
21 changes: 21 additions & 0 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,27 @@ You should get a pretty XUnit XML report like this:
</testsuite>
</testsuites>

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

<?xml version="1.0" encoding="UTF-8"?>
<testsuites duration="1.249">
<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">
<testcase classname="googletesting" name="google homepage title is the one expected" time="0.813"/>
<testcase classname="googletesting" name="main form is found" time="0.002"/>
<testcase classname="googletesting" name="google title is ok" time="0.416"/>
<testcase classname="googletesting" name="search term has been submitted" time="0.017"/>
<testcase classname="googletesting" name="results count is 10+" time="0.001"/>
<failure type="fail">google search for "casperjs" retrieves 10 or more results</failure>
<system-out/>
</testsuite>
</testsuites>

CasperJS own tests
------------------

Expand Down
2 changes: 1 addition & 1 deletion modules/xunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
Expand Down
22 changes: 22 additions & 0 deletions tests/suites/xunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
0