Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make gradle not to mark build failed if no tests are found

Tags:

gradle

As the title says, how can I make gradle not to fail a test task if no tests are found? I ran into this problem when I was using the --tests command line option with a multi-subproject project. For instance, this command below will run all tests in class FooTest from subproject A:
gradle test --tests com.foo.bar.FooTest

However, this command fails because of something like this:

Execution failed for task ':B:test'.
> No tests found for given includes: [com.foo.bar.FooTest]

BTW, I know something like below will succeed. But is it possible to make it succeed even with the test task? It's kind of annoying to type a test task name longer than test.

gradle :A:test --tests com.foo.bar.FooTest

like image 937
JBT Avatar asked Oct 01 '14 17:10

JBT


People also ask

How do you exclude test cases in build Gradle?

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.

Does Gradle build also run tests?

In the Gradle project, you can create and run tests the same way you do in any other project.

What does Gradle clean test do?

cleanJar will delete the JAR file created by the jar task, and cleanTest will delete the test results created by the test task.


1 Answers

The behavior you described is the current Gradle behavior, there is already a ticket on Gradle forum, see https://discuss.gradle.org/t/multi-module-build-fails-with-tests-filter/25835

Based on the solution described in this ticket, you can do something like that to disable the 'failIfNoTest' default behavior:

In your root project build (or better: in an InitScript in your Gradle USER_HOME dir, to make this behavior available for all your local projects)

gradle.projectsEvaluated {
    subprojects {
        // TODO: filter projects that does not have test task...
        test {
            filter {
                setFailOnNoMatchingTests(false)
            }
        }
    }
}

Then you can execute the following command without having errors if the given test doesn't exist in all sub-projects:

gradle test --tests com.foo.bar.FooTest
like image 124
M.Ricciuti Avatar answered Oct 13 '22 10:10

M.Ricciuti