TestFilter

interface TestFilter(source)

Allows filtering tests for execution. 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"
      }
  }

Since

1.10

Functions

Link copied to clipboard
abstract fun excludeTest(className: String, methodName: String): TestFilter
Excludes a test method specified by test class name and method name.
Link copied to clipboard
abstract fun excludeTestsMatching(testNamePattern: String): TestFilter
Appends a test name pattern to the exclusion filter.
Link copied to clipboard
Returns the excluded test name patterns.
Link copied to clipboard
Returns the included test name patterns.
Link copied to clipboard
abstract fun includeTest(className: String, methodName: String): TestFilter
Add a test method specified by test class name and method name.
Link copied to clipboard
abstract fun includeTestsMatching(testNamePattern: String): TestFilter
Appends a test name pattern to the inclusion filter.
Link copied to clipboard
Returns whether the task should fail if no matching tests where found.
Link copied to clipboard
abstract fun setExcludePatterns(testNamePatterns: Array<String>): TestFilter
Sets the test name patterns to be excluded in the filter.
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.
Link copied to clipboard
abstract fun setIncludePatterns(testNamePatterns: Array<String>): TestFilter
Sets the test name patterns to be included in the filter.