Skip to content

Commit 8b91cb9

Browse files
committed
build.gradle: failOnTestError runs only if junitXml is present
1 parent fbeee91 commit 8b91cb9

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

build.gradle

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,18 @@ task failOnTestError() {
219219
description 'evaluate junit result and fail on error'
220220
doLast {
221221

222-
def junitResult = new XmlSlurper().parse(file('TESTS-TestSuites.xml'))
223-
def failures = junitResult.'**'.findAll { it.name() == 'failure' }
224-
def errors = junitResult.'**'.findAll { it.name() == 'errors' }
225-
226-
if (failures || errors) {
227-
def amount = failures.size() + errors.size()
228-
throw new GradleException(amount + " JUnit tests failed. Check the test report for details.")
222+
def juniXml = file('TESTS-TestSuites.xml')
223+
if(juniXml.exists()){
224+
def junitResult = new XmlSlurper().parse(juniXml)
225+
def failures = junitResult.'**'.findAll { it.name() == 'failure' }
226+
def errors = junitResult.'**'.findAll { it.name() == 'errors' }
227+
228+
if (failures || errors) {
229+
def amount = failures.size() + errors.size()
230+
throw new GradleException(amount + " JUnit tests failed. Check the test report for details.")
231+
}
229232
}
230233
}
231-
232234
}
233235
buildAndRunTests.configure { finalizedBy failOnTestError }
234236
check.dependsOn buildAndRunTests

0 commit comments

Comments
 (0)