diff --git a/plugins/edc-build/src/main/java/org/eclipse/edc/plugins/edcbuild/conventions/TestConvention.java b/plugins/edc-build/src/main/java/org/eclipse/edc/plugins/edcbuild/conventions/TestConvention.java index ecd04b05..221e0b31 100644 --- a/plugins/edc-build/src/main/java/org/eclipse/edc/plugins/edcbuild/conventions/TestConvention.java +++ b/plugins/edc-build/src/main/java/org/eclipse/edc/plugins/edcbuild/conventions/TestConvention.java @@ -17,6 +17,7 @@ import org.gradle.api.Project; import org.gradle.api.tasks.testing.Test; import org.gradle.api.tasks.testing.logging.TestExceptionFormat; +import org.jetbrains.annotations.NotNull; import static java.util.Optional.ofNullable; @@ -25,24 +26,45 @@ */ class TestConvention implements EdcConvention { private static void determineJunitPlatform(Test testTask) { + // parse task exclusion + var excludedTagsProperty = System.getProperty("excludeTags"); + var excludedTags = getTags(excludedTagsProperty); + + // Target all type of test e.g. -DrunAllTests="true" var runAllTests = Boolean.parseBoolean(System.getProperty("runAllTests", "false")); if (runAllTests) { - testTask.useJUnitPlatform(); + // honor excluded tags -> blacklisting + if (excludedTags.length > 0) { + testTask.useJUnitPlatform(platform -> platform.excludeTags(excludedTags)); + } else { + testTask.useJUnitPlatform(); + } } else { var includeTagsProperty = System.getProperty("includeTags"); - var tags = ofNullable(includeTagsProperty) - .map(prop -> prop.split(",")) - .orElse(new String[0]); + var includedTags = getTags(includeTagsProperty); - if (tags.length > 0) { - testTask.useJUnitPlatform(platform -> platform.includeTags(tags)); + // white-list included tags... + if (includedTags.length > 0) { + testTask.useJUnitPlatform(platform -> platform.includeTags(includedTags)); + //... and possibly black-list excluded tags + if (excludedTags.length > 0) { + testTask.useJUnitPlatform(platform -> platform.excludeTags(excludedTags)); + } } else { + // no point in evaluating other excluded tags, if only unit tests are run testTask.useJUnitPlatform(platform -> platform.excludeTags("IntegrationTest")); } } } + @NotNull + private static String[] getTags(String tagsSeparatedByComma) { + return ofNullable(tagsSeparatedByComma) + .map(prop -> prop.split(",")) + .orElse(new String[0]); + } + @Override public void apply(Project target) { target.getTasks().withType(Test.class, testTask -> {