It took some time, but my PR to CasperJS has landed.
Now you can fail a test with a custom value for a testcase
node’s name
property like:
casper.test.fail('A custom message', {name: 'custom name'});
tl;dr
When using the --xunit=/path/to/report.xml
casperjs is using the message
as property for the name
of the testcase
node in xml report. This means if you fail a test like:
casper.fail('A really long and expressive message');
the resulting xml would look something like:
<testcase classname="a-custom-test-case-name" name="A really long and expressive message" time="0.023">
<failure type="fail">A really long and expressive message</failure>
</testcase>
Imagine you want to capture and provide an stacktrace from a jsp page
as message..
Here comes the optional argument FTW.
As stated above, pass in a arbitrary object with a name
property like:
var stacktrace = casper.fictional_method_to_capture_stacktrace();
casper.test.fail(stacktrace, {name: 'stacktrace'});
and you’ll get
<testcase classname="a-custom-test-case-name" name="stacktrace" time="0.023">
<failure type="fail">Exception in thread "main" java.lang.NullPointerException
at Test.test(Test.java:6)
at Test.main(Test.java:10)
</failure>
</testcase>
Much better..