Skip to content

Commit

Permalink
[JUNIT_TEST_REPORT] Fix JUnit generated report to fit Ant and Maven S…
Browse files Browse the repository at this point in the history
…urfire schema.

Maven Surfire schema
Truncate time to 3 charcters after dot to fit new standards for junit:
http://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd

Ant schema
- Add missing errors attribute under testsuite node
- Remove skipped attribute from testsuites node as invalid argument
  • Loading branch information
lukzeg authored and luze-mobica committed May 31, 2021
1 parent 7d463ab commit 6933881
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions plugins/junit_tests_report/lib/junit_tests_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def post_build
def write_header( results, stream )
results[:counts][:time] = @time_result.reduce(0, :+)
stream.puts '<?xml version="1.0" encoding="utf-8" ?>'
stream.puts('<testsuites tests="%<total>d" failures="%<failed>d" skipped="%<ignored>d" time="%<time>f">' % results[:counts])
stream.puts('<testsuites tests="%<total>d" failures="%<failed>d" time="%<time>.3f">' % results[:counts])
end

def write_footer( stream )
Expand All @@ -53,7 +53,7 @@ def write_footer( stream )

def reorganise_results( results )
# Reorganise the output by test suite instead of by result
suites = Hash.new{ |h,k| h[k] = {collection: [], total: 0, success: 0, failed: 0, ignored: 0, stdout: []} }
suites = Hash.new{ |h,k| h[k] = {collection: [], total: 0, success: 0, failed: 0, ignored: 0, errors: 0, stdout: []} }
results[:successes].each do |result|
source = result[:source]
name = source[:file].sub(/\..{1,4}$/, "")
Expand Down Expand Up @@ -85,7 +85,7 @@ def reorganise_results( results )

def write_suite( suite, stream )
suite[:time] = @time_result.shift
stream.puts(' <testsuite name="%<name>s" tests="%<total>d" failures="%<failed>d" skipped="%<ignored>d" time="%<time>f">' % suite)
stream.puts(' <testsuite name="%<name>s" tests="%<total>d" failures="%<failed>d" skipped="%<ignored>d" errors="%<errors>d" time="%<time>.3f">' % suite)

suite[:collection].each do |test|
write_test( test, stream )
Expand Down Expand Up @@ -116,17 +116,17 @@ def write_test( test, stream )

case test[:result]
when :success
stream.puts(' <testcase name="%<test>s" time="%<unity_test_time>f"/>' % test)
stream.puts(' <testcase name="%<test>s" time="%<unity_test_time>.3f"/>' % test)
when :failed
stream.puts(' <testcase name="%<test>s" time="%<unity_test_time>f">' % test)
stream.puts(' <testcase name="%<test>s" time="%<unity_test_time>.3f">' % test)
if test[:message].empty?
stream.puts(' <failure />')
else
stream.puts(' <failure message="%s" />' % test[:message])
end
stream.puts(' </testcase>')
when :ignored
stream.puts(' <testcase name="%<test>s" time="%<unity_test_time>f">' % test)
stream.puts(' <testcase name="%<test>s" time="%<unity_test_time>.3f">' % test)
stream.puts(' <skipped />')
stream.puts(' </testcase>')
end
Expand Down

0 comments on commit 6933881

Please sign in to comment.