# 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(): Set<String>
Returns the excluded test name patterns.
getIncludePatterns
Link copied to clipboard
@Input
abstract fun getIncludePatterns(): Set<String>
Returns the included test name patterns.
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.
isFailOnNoMatchingTests
Link copied to clipboard
@Input
abstract fun isFailOnNoMatchingTests(): Boolean
Returns whether the task should fail if no matching tests where found.
setExcludePatterns
Link copied to clipboard
abstract fun setExcludePatterns(testNamePatterns: Array<String>): TestFilter
Sets the test name patterns to be excluded in the filter.
setFailOnNoMatchingTests
Link copied to clipboard
abstract fun setFailOnNoMatchingTests(failOnNoMatchingTests: Boolean)
Let the test task fail if a filter configuration was provided but no test matched the given configuration.
setIncludePatterns
Link copied to clipboard
abstract fun setIncludePatterns(testNamePatterns: Array<String>): TestFilter
Sets the test name patterns to be included in the filter.