Interface TestSpec


  • @Incubating
    public interface TestSpec
    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();
     

    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
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      TestSpec includeClass​(java.lang.String cls)
      Adds the target test class to the test execution.
      TestSpec includeClasses​(java.util.Collection<java.lang.String> classes)
      Adds the target test classes to the test execution.
      TestSpec includeMethod​(java.lang.String cls, java.lang.String method)
      Adds the target test method to the test execution.
      TestSpec includeMethods​(java.lang.String cls, java.util.Collection<java.lang.String> methods)
      Adds the target test methods to the test execution.
      TestSpec includePackage​(java.lang.String pkg)
      Adds all tests declared in the target package to the test execution.
      TestSpec includePackages​(java.util.Collection<java.lang.String> packages)
      Adds all tests declared in the target packages to the test execution.
      TestSpec includePattern​(java.lang.String pattern)
      Adds all test classes and methods to the test execution that matches the target pattern.
      TestSpec includePatterns​(java.util.Collection<java.lang.String> patterns)
      Adds all test classes and methods to the test execution that matches the target patterns.
    • Method Detail

      • includePackage

        TestSpec includePackage​(java.lang.String pkg)
        Adds all tests declared in the target package to the test execution.

        The effect is recursive, meaning that the tests defined in sub-packages will also be executed.

        Parameters:
        pkg - The target package.
        Returns:
        this
      • includePackages

        TestSpec includePackages​(java.util.Collection<java.lang.String> packages)
        Adds all tests declared in the target packages to the test execution.
        Parameters:
        packages - The target packages.
        Returns:
        this
        See Also:
        includePackage(String)
      • includeClass

        TestSpec includeClass​(java.lang.String cls)
        Adds the target test class to the test execution.

        The target class should be selected with its fully-qualified name.

        Parameters:
        cls - The fully-qualified name of the target class.
        Returns:
        this
      • includeClasses

        TestSpec includeClasses​(java.util.Collection<java.lang.String> classes)
        Adds the target test classes to the test execution.
        Parameters:
        classes - The fully-qualified name of the target classes.
        Returns:
        this
        See Also:
        includeClass(String)
      • includeMethod

        TestSpec includeMethod​(java.lang.String cls,
                               java.lang.String method)
        Adds the target test method to the test execution.

        The target method should be selected with its fully-qualified class name and with the name of the method.

        Parameters:
        cls - The fully-qualified name of the class containing the method.
        method - The name of the target method.
        Returns:
        this
      • includeMethods

        TestSpec includeMethods​(java.lang.String cls,
                                java.util.Collection<java.lang.String> methods)
        Adds the target test methods to the test execution.
        Parameters:
        cls - The fully-qualified name of the class containing the method.
        methods - The name of the target methods.
        Returns:
        this
        See Also:
        includeMethod(String, String)
      • includePattern

        TestSpec includePattern​(java.lang.String pattern)
        Adds all test classes and methods to the test execution that matches the target pattern.

        The patterns follow the rules of test filtering.

        Parameters:
        pattern - the pattern to select tests.
        Returns:
        this
      • includePatterns

        TestSpec includePatterns​(java.util.Collection<java.lang.String> patterns)
        Adds all test classes and methods to the test execution that matches the target patterns.
        Parameters:
        patterns - the patterns to select tests.
        Returns:
        this
        See Also:
        includePattern(String)