Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Skip Test

I am looking for a way to skip tests from one of the projects in a multi-build project. I don't want to use gradle build -x test because then it will skip test for all sub - projects.

Root

  • Sub P1
    • build.gradle
  • Sub P2
    • build.gradle
  • Sub P3
    • build.gradle
  • build.gradle
  • settings.gradle

I want to skip tests only for "Sub P3"

Can i configure my project(Sub P3) build file to skip tests?

like image 695
Vishal Singh Avatar asked Feb 08 '23 16:02

Vishal Singh


2 Answers

Due to official user guide, there are 3 ways to skip some task in gradle.

The first 2, are: using predicate and exception throwing. Predicates are resolved during the configuration phase and may not pass to your requirements. StopExecutionExeptionthrowing could be added to the doFirst of every test and be throwed according to some condition. Bit that seems to be not very clear, because you have to modify both root script to set the condition and subroject sripts test tasks.

And the 3rd one is - disabling the tasks. Every task, has a enabled property (default is true), which is preventing task execution, if it was set to false. Only thing you have to do is to set this property for test task in your subproject. This can be done in sub projects buil script root, as:

test.enabled = false

This will work, if you didn't specify custom test tasks, if you did, you can disable all test by task type, as:

project(':subProject').tasks.withType(Test){
    enabled = false
}

Previews 2 configurations must be included to the build script of the subproject, but since you have a root project, you can configure subprojecst from it's build script, via project() providing subproject's name:

project(':subProject').tasks.withType(Test){
    enabled = false
}
like image 113
Stanislav Avatar answered Feb 11 '23 15:02

Stanislav


For android there is no test task available in gradle

To skip unit tests in android you have to do this

android {
.
.
.
    testOptions {
        unitTests.all {
           enabled false
        }
    }
}
like image 37
Adeel Ahmad Avatar answered Feb 11 '23 14:02

Adeel Ahmad