# TestSpec

@Incubating
interface TestSpec(source)

Provides infrastructure to select which test classes, methods, and packages will be included in the test execution.

A complex example:

    TestLauncher testLauncher = projectConnection.newTestLauncher();
    testLauncher.withTestsFor(specs -> {
        specs.forTaskPath(":test")                                    // configure the test selection on the ':test' task
             .includePackage("org.pkg")                               // execute all tests declared the org.pkg package and its sub-packages
             .includeClass("com.MyTest")                              // execute the MyTest test class
             .includeMethod("com.OtherTest", Arrays.asList("verify")) // execute the OtherTest.verify() test method
             .includePattern("io.*")                                  // execute all tests matching to io.*
    }).run();

Content copied to clipboard

All methods on this interface (including the class and method selection) support patterns as arguments. The patterns follow the rules of test filtering.

The test execution will fail if any of the selected classes, methods, or patters have no matching tests.

#### Since

7.6

## Functions

includeClass
Link copied to clipboard
abstract fun includeClass(cls: String): TestSpec
Adds the target test class to the test execution.
includeClasses
Link copied to clipboard
abstract fun includeClasses(classes: Collection<String>): TestSpec
Adds the target test classes to the test execution.
includeMethod
Link copied to clipboard
abstract fun includeMethod(cls: String, method: String): TestSpec
Adds the target test method to the test execution.
includeMethods
Link copied to clipboard
abstract fun includeMethods(cls: String, methods: Collection<String>): TestSpec
Adds the target test methods to the test execution.
includePackage
Link copied to clipboard
abstract fun includePackage(pkg: String): TestSpec
Adds all tests declared in the target package to the test execution.
includePackages
Link copied to clipboard
abstract fun includePackages(packages: Collection<String>): TestSpec
Adds all tests declared in the target packages to the test execution.
includePattern
Link copied to clipboard
abstract fun includePattern(pattern: String): TestSpec
Adds all test classes and methods to the test execution that matches the target pattern.
includePatterns
Link copied to clipboard
abstract fun includePatterns(patterns: Collection<String>): TestSpec
Adds all test classes and methods to the test execution that matches the target patterns.