|
17 | 17 | import org.gradle.api.Project; |
18 | 18 | import org.gradle.api.tasks.testing.Test; |
19 | 19 | import org.gradle.api.tasks.testing.logging.TestExceptionFormat; |
| 20 | +import org.jetbrains.annotations.NotNull; |
20 | 21 |
|
21 | 22 | import static java.util.Optional.ofNullable; |
22 | 23 |
|
|
25 | 26 | */ |
26 | 27 | class TestConvention implements EdcConvention { |
27 | 28 | private static void determineJunitPlatform(Test testTask) { |
| 29 | + // parse task exclusion |
| 30 | + var excludedTagsProperty = System.getProperty("excludeTags"); |
| 31 | + var excludedTags = getTags(excludedTagsProperty); |
| 32 | + |
| 33 | + |
28 | 34 | // Target all type of test e.g. -DrunAllTests="true" |
29 | 35 | var runAllTests = Boolean.parseBoolean(System.getProperty("runAllTests", "false")); |
30 | 36 | if (runAllTests) { |
31 | | - testTask.useJUnitPlatform(); |
| 37 | + // honor excluded tags -> blacklisting |
| 38 | + if (excludedTags.length > 0) { |
| 39 | + testTask.useJUnitPlatform(platform -> platform.excludeTags(excludedTags)); |
| 40 | + } else { |
| 41 | + testTask.useJUnitPlatform(); |
| 42 | + } |
32 | 43 | } else { |
33 | 44 | var includeTagsProperty = System.getProperty("includeTags"); |
34 | | - var tags = ofNullable(includeTagsProperty) |
35 | | - .map(prop -> prop.split(",")) |
36 | | - .orElse(new String[0]); |
| 45 | + var includedTags = getTags(includeTagsProperty); |
37 | 46 |
|
38 | | - if (tags.length > 0) { |
39 | | - testTask.useJUnitPlatform(platform -> platform.includeTags(tags)); |
| 47 | + // white-list included tags... |
| 48 | + if (includedTags.length > 0) { |
| 49 | + testTask.useJUnitPlatform(platform -> platform.includeTags(includedTags)); |
| 50 | + //... and possibly black-list excluded tags |
| 51 | + if (excludedTags.length > 0) { |
| 52 | + testTask.useJUnitPlatform(platform -> platform.excludeTags(excludedTags)); |
| 53 | + } |
40 | 54 | } else { |
| 55 | + // no point in evaluating other excluded tags, if only unit tests are run |
41 | 56 | testTask.useJUnitPlatform(platform -> platform.excludeTags("IntegrationTest")); |
42 | 57 | } |
43 | 58 | } |
44 | 59 | } |
45 | 60 |
|
| 61 | + @NotNull |
| 62 | + private static String[] getTags(String tagsSeparatedByComma) { |
| 63 | + return ofNullable(tagsSeparatedByComma) |
| 64 | + .map(prop -> prop.split(",")) |
| 65 | + .orElse(new String[0]); |
| 66 | + } |
| 67 | + |
46 | 68 | @Override |
47 | 69 | public void apply(Project target) { |
48 | 70 | target.getTasks().withType(Test.class, testTask -> { |
|
0 commit comments