Outputting additional information into the JUnit XML

Since it is available and seems to be desired by the JUnit spec [ http://stackoverflow.com/questions/4922867/junit-xml-format-specification-that-hudson-supports ]
This commit is contained in:
Kelvin Luck 2013-01-08 10:38:29 +00:00
parent 8e85e593bd
commit ef8f191c46
3 changed files with 37 additions and 35 deletions

View File

@ -42,16 +42,17 @@
function(expectation) function(expectation)
{ {
if (!expectation.passed()) { if (!expectation.passed()) {
failureMessages.push((failureMessages.length + 1) + ': ' + expectation.message); failureMessages.push(expectation.message);
} }
} }
); );
} }
return { return {
assertions: spec.results().items_.length,
className: getNestedSuiteName(spec.suite), className: getNestedSuiteName(spec.suite),
name: spec.description, name: spec.description,
time: spec.duration / 1000, time: spec.duration / 1000,
failureMessage: failureMessages.join(' ') failureMessages: failureMessages
}; };
} }
) )

View File

@ -209,36 +209,37 @@
function(suite) function(suite)
{ {
var failures = 0, var failures = 0,
data = { data = {
name: getNestedSuiteName(suite), name: getNestedSuiteName(suite),
time: suite.duration / 1000, time: suite.duration / 1000,
timestamp: suite.timestamp, timestamp: suite.timestamp,
tests: suite.specs().length, tests: suite.specs().length,
errors: 0, // TODO: These exist in the JUnit XML but not sure how they map to jasmine things errors: 0, // TODO: These exist in the JUnit XML but not sure how they map to jasmine things
testcases: suite.specs().map( testcases: suite.specs().map(
function(spec) function(spec)
{ {
var failureMessages = []; var failureMessages = [];
if (spec.results().failedCount) { if (spec.results().failedCount) {
failures ++; failures ++;
spec.results().items_.forEach( spec.results().items_.forEach(
function(expectation) function(expectation)
{ {
if (!expectation.passed()) { if (!expectation.passed()) {
failureMessages.push((failureMessages.length + 1) + ': ' + expectation.message); failureMessages.push(expectation.message);
} }
}
);
} }
); return {
} assertions: spec.results().items_.length,
return { className: getNestedSuiteName(spec.suite),
className: getNestedSuiteName(spec.suite), name: spec.description,
name: spec.description, time: spec.duration / 1000,
time: spec.duration / 1000, failureMessages: failureMessages
failureMessage: failureMessages.join(' ') };
}; }
} )
) };
};
data.failures = failures; data.failures = failures;
return data; return data;
} }

View File

@ -3,10 +3,10 @@
<% testsuites.forEach(function(testsuite) { %> <% testsuites.forEach(function(testsuite) { %>
<testsuite name="<%- testsuite.name %>" errors="<%= testsuite.errors %>" tests="<%= testsuite.tests %>" failures="<%= testsuite.failures %>" time="<%= testsuite.time %>" timestamp="<%= testsuite.timestamp %>"> <testsuite name="<%- testsuite.name %>" errors="<%= testsuite.errors %>" tests="<%= testsuite.tests %>" failures="<%= testsuite.failures %>" time="<%= testsuite.time %>" timestamp="<%= testsuite.timestamp %>">
<% testsuite.testcases.forEach(function(testcase) { %> <% testsuite.testcases.forEach(function(testcase) { %>
<testcase classname="<%- testcase.classname %>" name="<%- testcase.name %>" time="<%= testcase.time %>"> <testcase assertions="<%= testcase.assertions %>" classname="<%- testcase.classname %>" name="<%- testcase.name %>" time="<%= testcase.time %>">
<% if (testcase.failureMessage) { %> <% testcase.failureMessages.forEach(function(message) { %>
<failure><%= testcase.failureMessage %></failure> <failure><%= message %></failure>
<% } %> <% }) %>
</testcase> </testcase>
<% }) %> <% }) %>
</testsuite> </testsuite>