Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle ignoreFailures test property

Tags:

java

junit

gradle

My build.gradle file is like the following :

apply plugin: "java"
...
test {
  ...
  ignoreFailures = "$ignoreFailureProp"
}

and a gradle.properties with

ignoreFailureProp=false

When executed gradle clean build, the unit test failures do not mark the build as failed.

I know the default behaviour is to fail the build, but I want to explicitly set it through a property, to change in without modifying the build file

like image 506
facewindu Avatar asked Jun 26 '14 08:06

facewindu


People also ask

How do I run a single unit test in Gradle?

You can do gradle -Dtest. single=ClassUnderTestTest test if you want to test single class or use regexp like gradle -Dtest. single=ClassName*Test test you can find more examples of filtering classes for tests under this link.

How do I test Gradle tasks?

Within IntelliJ IDEA, find the check task in the Gradle tool window under verification. Double click it to run. Check is also run when you run the build task, thanks to a task dependency setup by the base plugin. Gradle runs the assemble task then check.

How do I run a test using Gradle command?

Use the command ./gradlew test to run all tests.

How do I skip test cases in Gradle build?

To skip any task from the Gradle build, we can use the -x or –exclude-task option. In this case, we'll use “-x test” to skip tests from the build. As a result, the test sources aren't compiled, and therefore, aren't executed.


1 Answers

You do not have to use a file like gradle.properties.

If you change your build.gradle to:

apply plugin: "java"
...
test {
  ...
  ignoreFailures Boolean.getBoolean("test.ignoreFailures")
}

and invoke the tests with gradle -Dtest.ignoreFailures=true clean build you are done without editing any file. Note that, if you do not set the parameter or set it to any other value than true (case in-sensitive) failures are not ignored (ie. the default behaviour).

like image 144
Würgspaß Avatar answered Sep 17 '22 07:09

Würgspaß