Search code examples
javaunit-testinggradle

Gradle: how to exclude some tests?


My src/test/ folder includes both unit and functional tests. The classpath of functional tests has the word cucumber, whereas the unit tests do not. So, how can I run the unit tests only?

Thank you very much.

P.S.: I know it is easy to use the "include" logic to select tests. For example, to only run the functional tests in my case, I can simply use this
./gradlew test -Dtest.single=cucumber/**/
However, I don't know how to exclude tests in a simple way.

BTW, I am using gradle 1.11.


Solution

  • The documentation of the task explains it, with an example and everything:

    apply plugin: 'java' // adds 'test' task
    
    test {
      // ...
    
      // explicitly include or exclude tests
      include 'org/foo/**'
      exclude 'org/boo/**'
    
      // ...
    }