/
inclusion-exclusion.apt.vm
252 lines (209 loc) · 8.24 KB
/
inclusion-exclusion.apt.vm
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
------
Inclusions and Exclusions of Tests
------
Allan Ramirez
------
2010-01-09
------
~~ Licensed to the Apache Software Foundation (ASF) under one
~~ or more contributor license agreements. See the NOTICE file
~~ distributed with this work for additional information
~~ regarding copyright ownership. The ASF licenses this file
~~ to you 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.
~~ NOTE: For help with the syntax of this file, see:
~~ http://maven.apache.org/doxia/references/apt-format.html
Inclusions and Exclusions of Tests
* Inclusions
By default, the ${thisPlugin} Plugin will automatically include all test classes
with the following wildcard patterns:
#{if}(${project.artifactId}=="maven-surefire-plugin")
* <<<"**/Test*.java">>> - includes all of its subdirectories and all Java
filenames that start with "Test".
* <<<"**/*Test.java">>> - includes all of its subdirectories and all Java
filenames that end with "Test".
* <<<"**/*Tests.java">>> - includes all of its subdirectories and all Java
filenames that end with "Tests".
* <<<"**/*TestCase.java">>> - includes all of its subdirectories and all Java
filenames that end with "TestCase".
#{else}
* <<<"**/IT*.java">>> - includes all of its subdirectories and all Java
filenames that start with "IT".
* <<<"**/*IT.java">>> - includes all of its subdirectories and all Java
filenames that end with "IT".
* <<<"**/*ITCase.java">>> - includes all of its subdirectories and all Java
filenames that end with "ITCase".
#{end}
[]
If the test classes do not follow the default wildcard patterns, then override them by configuring the ${thisPlugin}
Plugin and specify the tests you want to include (or exclude) or another patterns.
+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<configuration>
<includes>
<include>Sample.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
+---+
* Exclusions
There are certain times when some tests are causing the build to fail.
Excluding them is one of the best workarounds to continue the build.
Exclusions can be done by configuring the <<<excludes>>> property of the
plugin.
#{if}(${project.artifactId}=="maven-surefire-plugin")
+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<configuration>
<excludes>
<exclude>**/TestCircle.java</exclude>
<exclude>**/TestSquare.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
+---+
#{else}
+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<configuration>
<excludes>
<exclude>**/CircleIT.java</exclude>
<exclude>**/SquareIT.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
+---+
#{end}
* Regular Expression Support
An include/exclude pattern can be an ant-style path expression, but
regular expressions are also supported through this syntax:
+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<configuration>
<includes>
<include>%regex[.*(Cat|Dog).*Test.*]</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
+---+
Note the syntax <<<%regex[expr]>>>, where <<<expr>>> is the actual expression and the rest is just wrapping. Also
note the following about the use of regular expressions:
* Regex matches are done over <<<*.class>>> files and not <<<*.java>>> files
* Regex matches are done over paths using slashes ("<<</>>>") and not package names using dots ("<<<.>>>"), so the
"<<<.>>>" in <<<pkg.*Slow.*.class>>> is a regex metacharacter, which happens to match any character, notably
the (forward) slashes ("<<</>>>") that make up the path. Slashes here are <forward>, even on Windows
* The trailing <<<.class>>> is interpreted literally, and not as a regular expression ("<<<\.class>>>" does not
work here)
* Multiple Formats in One
As of ${thisPlugin} Plugin 2.19, a complex syntax is supported in one parameter (JUnit 4, JUnit 4.7+, TestNG):
+---+
[...]
<include>%regex[.*(Cat|Dog).*], !%regex[pkg.*Slow.*.class], pkg/**/*Fast*.java, Basic????, !Unstable*</include>
[...]
<exclude>%regex[pkg.*Slow.*.class], Unstable*</exclude>
[...]
+---+
This syntax can be used in parameters: <<<test>>>, <<<includes>>>, <<<excludes>>>, <<<includesFile>>>, <<<excludesFile>>>.
Exclamation mark (!) excludes tests. The syntax in parameter <<<excludes>>> and <<<excludesFile>>> should not use (!).
The character (?) within non-regex pattern replaces one character in file name or path. The file extensions are not
mandatory in non-regex patterns, and packages with slash can be used. The regex validates fully qualified class file.
The regex supports '.class' file extension only. Note the regex comments, marked by (#) character, are unsupported.
* Fully qualified class name
As of ${thisPlugin} Plugin 2.19.1, the syntax with fully qualified class names or packages can be used, e.g.:
+---+
[...]
<include>my.package.*, another.package.*</include>
[...]
<exclude>my.package.???ExcludedTest, another.package.*ExcludedTest</exclude>
[...]
+---+
The character (?) replaces single character and (*) represents zero or more characters.
Multiple formats can be additionally combined.
This syntax can be used in parameters: <<<test>>>, <<<includes>>>, <<<excludes>>>, <<<includesFile>>>, <<<excludesFile>>>.
* Tests from dependencies
In order to scan dependencies by the ${thisPlugin} plugin and find the test classes to execute in the dependencies,
use the MOJO parameter <<<dependenciesToScan>>> and configure it as necessary.
Dependencies can be specified using the <<<groupId[:artifactId[:type[:classifier][:version]]]>>> format, and must
already be <<<dependency>>> elements in scope.
<Note:> Support for version, type and classifier was introduced in version <<<3.0.0-M4>>>. When using earlier versions,
${thisPlugin} will fail with an <<<IllegalArgumentException>>> if more than groupId and artifactId are specified.
+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<configuration>
<dependenciesToScan>
<dependency>org.acme:project-a</dependency>
<dependency>org.acme:project-b:test-jar</dependency>
<dependency>org.acme:project-c:*:tests-jdk15</dependency>
</dependenciesToScan>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
+---+
The configuration above will search for test classes in:
* All dependencies with the groupId <<<org.acme>>> and artifactId <<<project-a>>>
* All dependencies with the groupId <<<org.acme>>> and artifactId <<<project-b>>> and type <<<test-jar>>>
* All dependencies with the groupId <<<org.acme>>> and artifactId <<<project-c>>> and classifier <<<tests-jdk15>>>