# TestFilter

interface TestFilter(source)

Allows filtering tests for execution. Class-based and non-class-based tests are filtered using the same selection logic. Classes can be selected by their simple, fully qualified names or partial matches on class name or package. Methods can be selected by their full names, containing class or partial matches. Non-class-based tests are converted to package-like names using the relative path from their test definition directory. Some examples:

      apply plugin: 'java'

      test {
          filter {
             //specific test class, this can match 'SomeTest' class and corresponding method under any package
             includeTestsMatching("SomeTest")
             includeTestsMatching("SomeTest.someTestMethod*")

             //specific test class
             includeTestsMatching("org.gradle.SomeTest")

             //specific test class and method
             includeTestsMatching("org.gradle.SomeTest.someSpecificFeature")
             includeTest("org.gradle.SomeTest", "someTestMethod")

             //specific test method, use wildcard
             includeTestsMatching("*SomeTest.someSpecificFeature")

             //specific test class, wildcard for packages
             includeTestsMatching("*.SomeTest")

             //all classes in package, recursively
             includeTestsMatching("com.gradle.tooling.*")

             //all integration tests, by naming convention
             includeTestsMatching("*IntegTest")

             //only ui tests from integration tests, by some naming convention
             includeTestsMatching("*IntegTest*ui")

             //exclude a specific test by its name
             excludeTestsMatching("*canDoSomethingSpecific")
             //excluding tests by name also works for test names which have spaces
             excludeTestsMatching("*can do something specific")
          }
      }

Content copied to clipboard

#### Since

1.10 General information about filtering.Special notes about filtering non-class-based tests.

## Functions

excludeTest
Link copied to clipboard
abstract fun excludeTest(className: String, methodName: String): TestFilter
Excludes a test method specified by test class name and method name.
excludeTestsMatching
Link copied to clipboard
abstract fun excludeTestsMatching(testNamePattern: String): TestFilter
Appends a test name pattern to the exclusion filter.
getExcludePatterns
Link copied to clipboard
@Input
abstract fun getExcludePatterns(): SetProperty<String>
Returns the excluded test name patterns.
getFailOnNoMatchingTests
Link copied to clipboard
@Input
abstract fun getFailOnNoMatchingTests(): Property<Boolean>
Defines whether the task should fail if no matching tests where found.
getIncludePatterns
Link copied to clipboard
@Input
abstract fun getIncludePatterns(): SetProperty<String>
Returns the included test name patterns.
getIsFailOnNoMatchingTests
Link copied to clipboard
@Internal
open fun getIsFailOnNoMatchingTests(): Property<Boolean>
Used for Kotlin source compatibility.
includeTest
Link copied to clipboard
abstract fun includeTest(className: String, methodName: String): TestFilter
Add a test method specified by test class name and method name.
includeTestsMatching
Link copied to clipboard
abstract fun includeTestsMatching(testNamePattern: String): TestFilter
Appends a test name pattern to the inclusion filter.