CasperJS – fail test with custom testcase-name in xml report

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..

This entry was posted in javascript and tagged , . Bookmark the permalink.

One Response to CasperJS – fail test with custom testcase-name in xml report

  1. shoes with lifts says:

    Very interesting points you have observed, thanks for putting up.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>