Maven surefire plugin behavior in Gradle


(Yurii) #1

Hello, I am new to gradle and I am migrating from maven to gradle.
Currently, I am trying to achive Maven Surefire plugin behavior in gradle and I have wrote next code:

subprojects{
   test{
        include "**/Test*.java"
        include "**/*Test.java"
        include "**/*Tests.java"
        include "**/*TestCase.java"
   }
}

Unfotunatly, it does not work as I expected and just excludes ALL tests from my project.


(Pierre) #2

Hi,

I think this is because the include/exclude applies to classes, not to sources.

Note that the Test task is able to detect JUnit tests automatically. Unless you want to restrict tests executed by a task, you do not need to worry with exclude/include configuration.


(Yurii) #3

thanks for your answer.
I was not clear in my question
As a result i am expecting to exclude all tests which don’t match that patterns.


(Pierre) #4

Hi,

Reference class files, not source files, and it will work:

test {
    include '**/*Test.class'
    include '**/*TestCase.class'
}

But if you have tests that should not run, you probably should move them to another SourceSet.