-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
TestSpec.java
126 lines (114 loc) · 4.49 KB
/
TestSpec.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.tooling;
import org.gradle.api.Incubating;
import java.util.Collection;
/**
* Provides infrastructure to select which test classes, methods, and packages will be included in the test execution.
* <p>
* A complex example:
* <pre>
* 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();
* </pre>
* <p>
* All methods on this interface (including the class and method selection) support patterns as arguments. The patterns follow the rules of
* <a href="https://docs.gradle.org/current/userguide/java_testing.html#test_filtering">test filtering</a>.
* <p>
* The test execution will fail if any of the selected classes, methods, or patters have no matching tests.
*
* @since 7.6
*/
@Incubating
public interface TestSpec {
/**
* Adds all tests declared in the target package to the test execution.
* <p>
* The effect is recursive, meaning that the tests defined in sub-packages will also be executed.
*
* @param pkg The target package.
* @return this
*/
TestSpec includePackage(String pkg);
/**
* Adds all tests declared in the target packages to the test execution.
*
* @see #includePackage(String)
* @param packages The target packages.
* @return this
*/
TestSpec includePackages(Collection<String> packages);
/**
* Adds the target test class to the test execution.
* <p>
* The target class should be selected with its fully-qualified name.
*
* @param cls The fully-qualified name of the target class.
* @return this
*/
TestSpec includeClass(String cls);
/**
* Adds the target test classes to the test execution.
*
* @see #includeClass(String)
* @param classes The fully-qualified name of the target classes.
* @return this
*/
TestSpec includeClasses(Collection<String> classes);
/**
* Adds the target test method to the test execution.
* <p>
* The target method should be selected with its fully-qualified class name and with the name of the method.
*
* @param cls The fully-qualified name of the class containing the method.
* @param method The name of the target method.
* @return this
*/
TestSpec includeMethod(String cls, String method);
/**
* Adds the target test methods to the test execution.
*
* @see #includeMethod(String, String)
* @param cls The fully-qualified name of the class containing the method.
* @param methods The name of the target methods.
* @return this
*/
TestSpec includeMethods(String cls, Collection<String> methods);
/**
* Adds all test classes and methods to the test execution that matches the target pattern.
* <p>
* The patterns follow the rules of
* <a href="https://docs.gradle.org/current/userguide/java_testing.html#test_filtering">test filtering</a>.
*
* @param pattern the pattern to select tests.
* @return this
*/
TestSpec includePattern(String pattern);
/**
* Adds all test classes and methods to the test execution that matches the target patterns.
*
* @see #includePattern(String)
* @param patterns the patterns to select tests.
* @return this
*/
TestSpec includePatterns(Collection<String> patterns);
}