Skip to content

Commit dd8cac7

Browse files
committed
build.gradle: added build fail on test fail
in case any of the executed tests failed, the build fails be default. Threfore the results are parsed from the junit result xml.
1 parent 84a91f6 commit dd8cac7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

build.gradle

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import de.itemis.mps.gradle.*
2-
2+
import groovy.xml.XmlSlurper
33
import java.time.LocalDate
44
import java.time.format.DateTimeFormatter
55
import java.time.format.FormatStyle
@@ -212,6 +212,16 @@ task buildAndRunTests(type: TestLanguages, dependsOn: buildLanguages) {
212212
report(format: 'frames', todir: "$buildDir/junitreport")
213213
}
214214
ant.echo("JUnit report placed into $buildDir/junitreport/index.html")
215+
216+
// evaluate junit result and fail on error
217+
def junitResult = new XmlSlurper().parse(file('TESTS-TestSuites.xml'))
218+
def failures = junitResult.'**'.findAll { it.name() == 'failure' }
219+
def errors = junitResult.'**'.findAll { it.name() == 'errors' }
220+
221+
if (failures || errors) {
222+
def amount = failures.size() + errors.size()
223+
throw new GradleException(amount + " JUnit tests failed. Check the test report for details.")
224+
}
215225
}
216226
}
217227

0 commit comments

Comments
 (0)