Fail Gradle build when JUnit test is marked as ignored
I have a Java project in which I am running gradle test
. I would like to accomplish this task in case any test gets ignored by @Ignore
annotation .
I am currently seeing when tests are being ignored using the following task config test
in my file build.gradle
:
test {
testLogging {
events = ["passed", "failed", "skipped"]
}
}
With this configuration, an ignored test result results in the execution of a log statement, for example:
TestClass > testName SKIPPED
but not:
TestClass > testName PASSED
or
TestClass > testName FAILED
How can I achieve my goal in order to actually complete this task?
+3
stkent
source
to share
1 answer
Haven't tested this, but it might work:
test {
afterTest { descriptor, result ->
if (result.resultType == TestResult.ResultType.SKIPPED) {
throw new GradleException("Do not ignore test cases")
}
}
}
Literature:
-
Test.afterTest
-
TestResult.ResultType
+1
andrew
source
to share