Skip to content

Commit a6dfe08

Browse files
committed
Dangerfile: handle maven-surefire-plugin reports.
1 parent bd07698 commit a6dfe08

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

Dangerfile

+44
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,50 @@ else
450450
end
451451
end
452452

453+
# Handle `mvn test` reports
454+
# maven-surefire-plugin generates multiple XML files (one result file per test class).
455+
#
456+
# Example:
457+
# <testsuite name="ru.mystamps.web.service.CronServiceImplTest" time="0.175" tests="7" errors="0" skipped="0" failures="2">
458+
# <testcase name="sendDailyStatistics() should prepare report and pass it to mail service" classname="ru.mystamps.web.service.CronServiceImplTest" time="0.107">
459+
# <failure message="Condition not satisfied: bla bla bla" type="org.spockframework.runtime.SpockComparisonFailure">
460+
# org.spockframework.runtime.SpockComparisonFailure: bla bla bla
461+
# </failure>
462+
# </testcase>
463+
# </testsuite>
464+
#
465+
test_reports_pattern = 'target/surefire-reports/TEST-*.xml'
466+
test_reports = Dir.glob(test_reports_pattern)
467+
if test_reports.empty?
468+
warn("Couldn't find #{test_reports_pattern}. maven-surefire-plugin results is unknown")
469+
else
470+
errors_count = 0
471+
test_reports.each do |file|
472+
doc = Nokogiri::XML(File.open(file))
473+
testsuite = doc.xpath('/testsuite').first
474+
failures = testsuite['failures'].to_i
475+
if failures == 0
476+
next
477+
end
478+
479+
testsuite.xpath('.//failure').each do |failure|
480+
errors_count += 1
481+
msg = failure.text
482+
tc = failure.parent
483+
file = tc['classname'].gsub(/\./, '/')
484+
path = "src/test/groovy/#{file}.groovy"
485+
if File.file?(path)
486+
file = path
487+
end
488+
# TODO: try to findout the test case and use it for highlighting line numbers
489+
file = github.html_link(file)
490+
testcase = tc['name']
491+
fail("maven-surefire-plugin error in #{file}:\nTest case `#{testcase}` fails with message:\n```\n#{msg}\n```")
492+
end
493+
end
494+
print_errors_summary 'maven-surefire-plugin', errors_count, 'https://github.com/php-coder/mystamps/wiki/unit-tests'
495+
end
496+
453497
# Handle `mvn findbugs:check` results
454498
#
455499
# Example:

pom.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@
430430
<commons.lang.version>3.4</commons.lang.version>
431431
<compiler.plugin.version>3.6.1</compiler.plugin.version>
432432
<coveralls.plugin.version>2.2.0</coveralls.plugin.version>
433+
434+
<!-- Disable XML reports by default. Enabled manually by passing -DdisableXmlReport=false in CI environment -->
435+
<disableXmlReport>true</disableXmlReport>
436+
433437
<enforcer.plugin.version>1.4.1</enforcer.plugin.version>
434438
<failsafe.plugin.version>2.19.1</failsafe.plugin.version>
435439
<fest.assert.version>2.0M8</fest.assert.version>
@@ -790,7 +794,7 @@
790794
<version>${surefire.plugin.version}</version>
791795
<configuration>
792796
<skipTests>${skipUnitTests}</skipTests>
793-
<disableXmlReport>true</disableXmlReport>
797+
<disableXmlReport>${disableXmlReport}</disableXmlReport>
794798
<!-- Run junit tests only (see #SUREFIRE-377) -->
795799
<testNGArtifactName>none:none</testNGArtifactName>
796800
</configuration>

src/main/scripts/ci/check-build-and-verify.sh

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then
5656
-Denforcer.skip=true \
5757
-Dmaven.resources.skip=true \
5858
-DskipMinify=true \
59+
-DdisableXmlReport=false \
5960
>test.log 2>&1 || TEST_FAIL=yes
6061
# run after tests for getting compiled sources
6162
mvn --batch-mode findbugs:check >findbugs.log 2>&1 || FINDBUGS_FAIL=yes

0 commit comments

Comments
 (0)