This closes #93 pull request at github/apache/ant repomaster
| @@ -281,6 +281,7 @@ Matthew Warman | |||
| Matthew Watson | |||
| Matthew Yanos | |||
| Matthias Bhend | |||
| Matthias Gutheil | |||
| Michael Bayne | |||
| Michael Clarke | |||
| Michael Davey | |||
| @@ -12,6 +12,13 @@ Fixed bugs: | |||
| has now been fixed. | |||
| Bugzilla Report 63446 | |||
| Other changes: | |||
| -------------- | |||
| * junitlauncher task now supports selecting test classes for execution, | |||
| based on the JUnit 5 tags, through the new "includeTags" and | |||
| "excludeTags" attributes. | |||
| Changes from Ant 1.10.5 TO Ant 1.10.6 | |||
| ===================================== | |||
| @@ -1167,6 +1167,10 @@ | |||
| <first>Matthias</first> | |||
| <last>Bhend</last> | |||
| </name> | |||
| <name> | |||
| <first>Matthias</first> | |||
| <last>Gutheil</last> | |||
| </name> | |||
| <name> | |||
| <first>Michael</first> | |||
| <last>Bayne</last> | |||
| @@ -129,6 +129,20 @@ | |||
| <th scope="col">Description</th> | |||
| <th scope="col">Required</th> | |||
| </tr> | |||
| <tr> | |||
| <td>includeTags</td> | |||
| <td>A comma separated list of <a href="https://junit.org/junit5/docs/current/user-guide/#writing-tests-annotations">JUnit 5 tags</a>, describing the tests to include. | |||
| <p><em>Since Ant 1.10.7</em></p> | |||
| </td> | |||
| <td>No</td> | |||
| </tr> | |||
| <tr> | |||
| <td>excludeTags</td> | |||
| <td>A comma separated list of <a href="https://junit.org/junit5/docs/current/user-guide/#writing-tests-annotations">JUnit 5 tags</a>, describing the tests to exclude. | |||
| <p><em>Since Ant 1.10.7</em></p> | |||
| </td> | |||
| <td>No</td> | |||
| </tr> | |||
| <tr> | |||
| <td>haltOnFailure</td> | |||
| <td>A value of <q>true</q> implies that build has to stop if any failure occurs in any of | |||
| @@ -268,5 +268,70 @@ | |||
| </testclasses> | |||
| </junitlauncher> | |||
| </target> | |||
| <target name="test-method-with-include-tag" depends="init"> | |||
| <!-- junitlauncher includeTags="fast, superfast" excludeTags="slow"--> | |||
| <junitlauncher includeTags=" fast , superfast" excludeTags=" slow"> | |||
| <test name="org.example.junitlauncher.jupiter.JupiterSampleTest" outputdir="${output.dir}"> | |||
| <listener classname="org.example.junitlauncher.Tracker" outputDir="${output.dir}" | |||
| resultFile="${test-method-with-include-tag.tracker}" if="test-method-with-include-tag.tracker" /> | |||
| </test> | |||
| </junitlauncher> | |||
| </target> | |||
| <target name="test-method-with-exclude-tag" depends="init"> | |||
| <junitlauncher excludeTags="slow"> | |||
| <test name="org.example.junitlauncher.jupiter.JupiterSampleTest" outputdir="${output.dir}"> | |||
| <listener classname="org.example.junitlauncher.Tracker" outputDir="${output.dir}" | |||
| resultFile="${test-method-with-exclude-tag.tracker}" if="test-method-with-exclude-tag.tracker" /> | |||
| </test> | |||
| </junitlauncher> | |||
| </target> | |||
| <target name="test-method-with-tag-2-classes" depends="init"> | |||
| <junitlauncher includeTags="fast"> | |||
| <test name="org.example.junitlauncher.jupiter.JupiterSampleTest" outputdir="${output.dir}"> | |||
| <listener classname="org.example.junitlauncher.Tracker" outputDir="${output.dir}" | |||
| resultFile="${test-method-with-tag-2-classes1.tracker}" if="test-method-with-tag-2-classes1.tracker" /> | |||
| </test> | |||
| <test name="org.example.junitlauncher.jupiter.JupiterTagSampleTest" outputdir="${output.dir}"> | |||
| <listener classname="org.example.junitlauncher.Tracker" outputDir="${output.dir}" | |||
| resultFile="${test-method-with-tag-2-classes2.tracker}" if="test-method-with-tag-2-classes2.tracker" /> | |||
| </test> | |||
| </junitlauncher> | |||
| </target> | |||
| <target name="test-method-with-tag-fileset" depends="init"> | |||
| <property name="junitlauncher.test.tracker.append.file" value="${output.dir}/${test-method-with-tag-fileset.tracker}"/> | |||
| <junitlauncher includeTags="fast"> | |||
| <testclasses outputdir="${output.dir}"> | |||
| <fileset dir="${build.classes.dir}"> | |||
| <include name="org/example/junitlauncher/jupiter/*" /> | |||
| </fileset> | |||
| <listener classname="org.example.junitlauncher.Tracker" outputDir="${output.dir}" | |||
| if="test-method-with-tag-fileset.tracker" /> | |||
| </testclasses> | |||
| </junitlauncher> | |||
| </target> | |||
| <target name="test-method-with-tag-fileset-fork" depends="init"> | |||
| <property name="junitlauncher.test.tracker.append.file" value="${output.dir}/${test-method-with-tag-fileset-fork.tracker}" /> | |||
| <junitlauncher includeTags="fast"> | |||
| <classpath refid="junit.engine.jupiter.classpath" /> | |||
| <classpath> | |||
| <pathelement location="${build.classes.dir}" /> | |||
| </classpath> | |||
| <classpath refid="junit.platform.classpath" /> | |||
| <testclasses outputdir="${output.dir}"> | |||
| <fileset dir="${build.classes.dir}"> | |||
| <include name="org/example/junitlauncher/jupiter/*" /> | |||
| </fileset> | |||
| <fork dir="${basedir}" includeJUnitPlatformLibraries="false"> | |||
| </fork> | |||
| <listener classname="org.example.junitlauncher.Tracker" outputDir="${output.dir}" | |||
| if="test-method-with-tag-fileset-fork.tracker" /> | |||
| </testclasses> | |||
| </junitlauncher> | |||
| </target> | |||
| </project> | |||
| @@ -18,6 +18,7 @@ | |||
| package org.apache.tools.ant.taskdefs.optional.junitlauncher; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.MagicNames; | |||
| import org.apache.tools.ant.Project; | |||
| @@ -34,6 +35,7 @@ import org.junit.platform.engine.discovery.DiscoverySelectors; | |||
| import org.junit.platform.launcher.EngineFilter; | |||
| import org.junit.platform.launcher.Launcher; | |||
| import org.junit.platform.launcher.LauncherDiscoveryRequest; | |||
| import org.junit.platform.launcher.TagFilter; | |||
| import org.junit.platform.launcher.TestExecutionListener; | |||
| import org.junit.platform.launcher.TestPlan; | |||
| import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; | |||
| @@ -463,6 +465,13 @@ public class LauncherSupport { | |||
| if (enginesToExclude != null && enginesToExclude.length > 0) { | |||
| requestBuilder.filters(EngineFilter.excludeEngines(enginesToExclude)); | |||
| } | |||
| // add any tag filters | |||
| if (this.launchDefinition.getIncludeTags().size() > 0) { | |||
| requestBuilder.filters(TagFilter.includeTags(this.launchDefinition.getIncludeTags())); | |||
| } | |||
| if (this.launchDefinition.getExcludeTags().size() > 0) { | |||
| requestBuilder.filters(TagFilter.excludeTags(this.launchDefinition.getExcludeTags())); | |||
| } | |||
| } | |||
| private enum StreamType { | |||
| @@ -39,18 +39,22 @@ import java.util.Collections; | |||
| import java.util.List; | |||
| import java.util.Optional; | |||
| import java.util.Properties; | |||
| import java.util.stream.Stream; | |||
| import static javax.xml.stream.XMLStreamConstants.END_DOCUMENT; | |||
| import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; | |||
| import static javax.xml.stream.XMLStreamConstants.START_DOCUMENT; | |||
| import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; | |||
| import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_EXCLUDE_TAGS; | |||
| import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_HALT_ON_FAILURE; | |||
| import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_INCLUDE_TAGS; | |||
| import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_PRINT_SUMMARY; | |||
| import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ELM_LAUNCH_DEF; | |||
| import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ELM_LISTENER; | |||
| import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ELM_TEST; | |||
| import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ELM_TEST_CLASSES; | |||
| /** | |||
| * Used for launching forked tests from the {@link JUnitLauncherTask}. | |||
| * <p> | |||
| @@ -140,6 +144,14 @@ public class StandaloneLauncher { | |||
| if (haltOnfFailure != null) { | |||
| forkedLaunch.setHaltOnFailure(Boolean.parseBoolean(haltOnfFailure)); | |||
| } | |||
| final String includeTags = reader.getAttributeValue(null, LD_XML_ATTR_INCLUDE_TAGS); | |||
| if (includeTags != null) { | |||
| Stream.of(includeTags.split(",")).forEach(i -> forkedLaunch.addIncludeTag(i)); | |||
| } | |||
| final String excludeTags = reader.getAttributeValue(null, LD_XML_ATTR_EXCLUDE_TAGS); | |||
| if (excludeTags != null) { | |||
| Stream.of(excludeTags.split(",")).forEach(e -> forkedLaunch.addExcludeTag(e)); | |||
| } | |||
| final String printSummary = reader.getAttributeValue(null, LD_XML_ATTR_PRINT_SUMMARY); | |||
| if (printSummary != null) { | |||
| forkedLaunch.setPrintSummary(Boolean.parseBoolean(printSummary)); | |||
| @@ -204,6 +216,8 @@ public class StandaloneLauncher { | |||
| private boolean haltOnFailure; | |||
| private List<TestDefinition> tests = new ArrayList<>(); | |||
| private List<ListenerDefinition> listeners = new ArrayList<>(); | |||
| private List<String> includeTags = new ArrayList<>(); | |||
| private List<String> excludeTags = new ArrayList<>(); | |||
| @Override | |||
| public List<TestDefinition> getTests() { | |||
| @@ -249,5 +263,23 @@ public class StandaloneLauncher { | |||
| public ClassLoader getClassLoader() { | |||
| return this.getClass().getClassLoader(); | |||
| } | |||
| void addIncludeTag(final String filter) { | |||
| this.includeTags.add(filter); | |||
| } | |||
| @Override | |||
| public List<String> getIncludeTags() { | |||
| return includeTags; | |||
| } | |||
| void addExcludeTag(final String filter) { | |||
| this.excludeTags.add(filter); | |||
| } | |||
| @Override | |||
| public List<String> getExcludeTags() { | |||
| return excludeTags; | |||
| } | |||
| } | |||
| } | |||
| @@ -36,6 +36,8 @@ public final class Constants { | |||
| public static final String LD_XML_ELM_TEST = "test"; | |||
| public static final String LD_XML_ELM_TEST_CLASSES = "test-classes"; | |||
| public static final String LD_XML_ATTR_HALT_ON_FAILURE = "haltOnFailure"; | |||
| public static final String LD_XML_ATTR_INCLUDE_TAGS = "includeTags"; | |||
| public static final String LD_XML_ATTR_EXCLUDE_TAGS = "excludeTags"; | |||
| public static final String LD_XML_ATTR_OUTPUT_DIRECTORY = "outDir"; | |||
| public static final String LD_XML_ATTR_INCLUDE_ENGINES = "includeEngines"; | |||
| public static final String LD_XML_ATTR_EXCLUDE_ENGINES = "excludeEngines"; | |||
| @@ -41,12 +41,17 @@ import java.util.Collections; | |||
| import java.util.Hashtable; | |||
| import java.util.List; | |||
| import java.util.Properties; | |||
| import java.util.StringTokenizer; | |||
| import java.util.concurrent.TimeoutException; | |||
| import java.util.stream.Collectors; | |||
| import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_EXCLUDE_TAGS; | |||
| import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_HALT_ON_FAILURE; | |||
| import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_INCLUDE_TAGS; | |||
| import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_PRINT_SUMMARY; | |||
| import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ELM_LAUNCH_DEF; | |||
| /** | |||
| * An Ant {@link Task} responsible for launching the JUnit platform for running tests. | |||
| * This requires a minimum of JUnit 5, since that's the version in which the JUnit platform launcher | |||
| @@ -75,6 +80,8 @@ public class JUnitLauncherTask extends Task { | |||
| private boolean printSummary; | |||
| private final List<TestDefinition> tests = new ArrayList<>(); | |||
| private final List<ListenerDefinition> listeners = new ArrayList<>(); | |||
| private List<String> includeTags = new ArrayList<>(); | |||
| private List<String> excludeTags = new ArrayList<>(); | |||
| public JUnitLauncherTask() { | |||
| } | |||
| @@ -158,6 +165,32 @@ public class JUnitLauncherTask extends Task { | |||
| this.printSummary = printSummary; | |||
| } | |||
| /** | |||
| * Tags to include. Will trim each tag. | |||
| * | |||
| * @param includes comma separated list of tags to include while running the tests. | |||
| * @since Ant 1.10.7 | |||
| */ | |||
| public void setIncludeTags(final String includes) { | |||
| final StringTokenizer tokens = new StringTokenizer(includes, ","); | |||
| while (tokens.hasMoreTokens()) { | |||
| includeTags.add(tokens.nextToken().trim()); | |||
| } | |||
| } | |||
| /** | |||
| * Tags to exclude. Will trim each tag. | |||
| * | |||
| * @param excludes comma separated list of tags to exclude while running the tests. | |||
| * @since Ant 1.10.7 | |||
| */ | |||
| public void setExcludeTags(final String excludes) { | |||
| final StringTokenizer tokens = new StringTokenizer(excludes, ","); | |||
| while (tokens.hasMoreTokens()) { | |||
| excludeTags.add(tokens.nextToken().trim()); | |||
| } | |||
| } | |||
| private void preConfigure(final TestDefinition test) { | |||
| if (test.getHaltOnFailure() == null) { | |||
| test.setHaltOnFailure(this.haltOnFailure); | |||
| @@ -233,6 +266,12 @@ public class JUnitLauncherTask extends Task { | |||
| if (this.haltOnFailure) { | |||
| writer.writeAttribute(LD_XML_ATTR_HALT_ON_FAILURE, "true"); | |||
| } | |||
| if (this.includeTags.size() > 0) { | |||
| writer.writeAttribute(LD_XML_ATTR_INCLUDE_TAGS, commaSeparatedListElements(includeTags)); | |||
| } | |||
| if (this.excludeTags.size() > 0) { | |||
| writer.writeAttribute(LD_XML_ATTR_EXCLUDE_TAGS, commaSeparatedListElements(excludeTags)); | |||
| } | |||
| // task level listeners | |||
| for (final ListenerDefinition listenerDef : this.listeners) { | |||
| if (!listenerDef.shouldUse(getProject())) { | |||
| @@ -294,6 +333,12 @@ public class JUnitLauncherTask extends Task { | |||
| } | |||
| } | |||
| private static String commaSeparatedListElements(final List<String> stringList) { | |||
| return stringList.stream() | |||
| .map(Object::toString) | |||
| .collect(Collectors.joining(", ")); | |||
| } | |||
| private int executeForkedTest(final ForkDefinition forkDefinition, final CommandlineJava commandlineJava) { | |||
| final LogOutputStream outStream = new LogOutputStream(this, Project.MSG_INFO); | |||
| final LogOutputStream errStream = new LogOutputStream(this, Project.MSG_WARN); | |||
| @@ -359,6 +404,16 @@ public class JUnitLauncherTask extends Task { | |||
| return haltOnFailure; | |||
| } | |||
| @Override | |||
| public List<String> getIncludeTags() { | |||
| return includeTags; | |||
| } | |||
| @Override | |||
| public List<String> getExcludeTags() { | |||
| return excludeTags; | |||
| } | |||
| @Override | |||
| public ClassLoader getClassLoader() { | |||
| return this.executionCL; | |||
| @@ -55,4 +55,15 @@ public interface LaunchDefinition { | |||
| */ | |||
| ClassLoader getClassLoader(); | |||
| /** | |||
| * @return Returns the list of tags which will be used to evaluate tests that need to be included | |||
| * in the test execution | |||
| */ | |||
| List<String> getIncludeTags(); | |||
| /** | |||
| * @return Returns the list of tags which will be used to evaluate tests that need to be excluded | |||
| * from the test execution | |||
| */ | |||
| List<String> getExcludeTags(); | |||
| } | |||
| @@ -23,6 +23,7 @@ import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.JUnitLauncherTask; | |||
| import org.apache.tools.ant.util.LoaderUtils; | |||
| import org.example.junitlauncher.jupiter.JupiterSampleTest; | |||
| import org.example.junitlauncher.jupiter.JupiterTagSampleTest; | |||
| import org.example.junitlauncher.vintage.AlwaysFailingJUnit4Test; | |||
| import org.example.junitlauncher.vintage.ForkedTest; | |||
| import org.example.junitlauncher.vintage.JUnit4SampleTest; | |||
| @@ -32,6 +33,7 @@ import org.junit.Rule; | |||
| import org.junit.Test; | |||
| import java.io.File; | |||
| import java.nio.file.Files; | |||
| import java.nio.file.Path; | |||
| import java.nio.file.Paths; | |||
| @@ -228,7 +230,7 @@ public class JUnitLauncherTaskTest { | |||
| final String targetName = "test-junit-ant-runtime-lib-excluded"; | |||
| try { | |||
| buildRule.executeTarget(targetName); | |||
| Assert.fail(targetName + " was expected to fail since JUnit platform libraries " + | |||
| Assert.fail(targetName + " was expected to fail since Ant runtime libraries " + | |||
| "weren't included in the classpath of the forked JVM"); | |||
| } catch (BuildException be) { | |||
| // expect a Error due to missing main class (which is part of Ant runtime libraries | |||
| @@ -313,6 +315,107 @@ public class JUnitLauncherTaskTest { | |||
| JUnit4SampleTest.class.getName(), "testBar")); | |||
| } | |||
| /** | |||
| * Tests execution of a test which is configured to execute only methods with a special tag | |||
| */ | |||
| @Test | |||
| public void testMethodWithIncludeTag() throws Exception { | |||
| final String target = "test-method-with-include-tag"; | |||
| final Path tracker2 = setupTrackerProperty(target); | |||
| buildRule.executeTarget(target); | |||
| // verify only that specific method was run | |||
| Assert.assertTrue("testMethodIncludeTagisExecuted was expected to be run", wasTestRun(tracker2, JupiterSampleTest.class.getName(), | |||
| "testMethodIncludeTagisExecuted")); | |||
| Assert.assertFalse("testMethodIncludeTagisNotExecuted was expected NOT to be run", wasTestRun(tracker2, JupiterSampleTest.class.getName(), | |||
| "testMethodIncludeTagisNotExecuted")); | |||
| } | |||
| /** | |||
| * Tests execution of a test which is configured to execute only methods without special tags | |||
| */ | |||
| @Test | |||
| public void testMethodWithExcludeTag() throws Exception { | |||
| final String target = "test-method-with-exclude-tag"; | |||
| final Path tracker2 = setupTrackerProperty(target); | |||
| buildRule.executeTarget(target); | |||
| // verify only that specific method was run | |||
| Assert.assertTrue("testMethodIncludeTagisExecuted was expected to be run", wasTestRun(tracker2, JupiterSampleTest.class.getName(), | |||
| "testMethodIncludeTagisExecuted")); | |||
| Assert.assertFalse("testMethodIncludeTagisNotExecuted was expected NOT to be run", wasTestRun(tracker2, JupiterSampleTest.class.getName(), | |||
| "testMethodIncludeTagisNotExecuted")); | |||
| } | |||
| /** | |||
| * Tests execution of a test which is configured to execute only methods with special tags, two classes specified | |||
| */ | |||
| @Test | |||
| public void testMethodWithTag2Classes() throws Exception { | |||
| final String target = "test-method-with-tag-2-classes"; | |||
| final Path tracker1 = setupTrackerProperty(target + "1"); | |||
| final Path tracker2 = setupTrackerProperty(target + "2"); | |||
| buildRule.executeTarget(target); | |||
| // verify only that specific method was run | |||
| Assert.assertTrue("testMethodIncludeTagisExecuted was expected to be run", wasTestRun(tracker1, JupiterSampleTest.class.getName(), | |||
| "testMethodIncludeTagisExecuted")); | |||
| Assert.assertFalse("testMethodIncludeTagisNotExecuted was expected NOT to be run", wasTestRun(tracker1, JupiterSampleTest.class.getName(), | |||
| "testMethodIncludeTagisNotExecuted")); | |||
| Assert.assertTrue("testMethodIncludeTagisExecutedTagSampleTest was expected to be run", wasTestRun(tracker2, JupiterTagSampleTest.class.getName(), | |||
| "testMethodIncludeTagisExecutedTagSampleTest")); | |||
| Assert.assertFalse("testMethodIncludeTagisNotExecutedTagSampleTest was expected NOT to be run", wasTestRun(tracker2, JupiterTagSampleTest.class.getName(), | |||
| "testMethodIncludeTagisNotExecutedTagSampleTest")); | |||
| Assert.assertFalse("testMethodIncludeTagisNotExecutedTagSampleTest2 was expected NOT to be run", wasTestRun(tracker2, JupiterTagSampleTest.class.getName(), | |||
| "testMethodIncludeTagisNotExecutedTagSampleTest2")); | |||
| } | |||
| /** | |||
| * Tests execution of a test which is configured to execute only methods with special tags, two classes specified | |||
| */ | |||
| @Test | |||
| public void testMethodWithTagFileSet() throws Exception { | |||
| final String target = "test-method-with-tag-fileset"; | |||
| final Path tracker = setupTrackerProperty(target); | |||
| buildRule.executeTarget(target); | |||
| // verify only that specific method was run | |||
| Assert.assertTrue("testMethodIncludeTagisExecuted was expected to be run", wasTestRun(tracker, JupiterSampleTest.class.getName(), | |||
| "testMethodIncludeTagisExecuted")); | |||
| Assert.assertFalse("testMethodIncludeTagisNotExecuted was expected NOT to be run", wasTestRun(tracker, JupiterSampleTest.class.getName(), | |||
| "testMethodIncludeTagisNotExecuted")); | |||
| Assert.assertTrue("testMethodIncludeTagisExecutedTagSampleTest was expected to be run", wasTestRun(tracker, JupiterTagSampleTest.class.getName(), | |||
| "testMethodIncludeTagisExecutedTagSampleTest")); | |||
| Assert.assertFalse("testMethodIncludeTagisNotExecutedTagSampleTest was expected NOT to be run", wasTestRun(tracker, JupiterTagSampleTest.class.getName(), | |||
| "testMethodIncludeTagisNotExecutedTagSampleTest")); | |||
| Assert.assertFalse("testMethodIncludeTagisNotExecutedTagSampleTest2 was expected NOT to be run", wasTestRun(tracker, JupiterTagSampleTest.class.getName(), | |||
| "testMethodIncludeTagisNotExecutedTagSampleTest2")); | |||
| } | |||
| /** | |||
| * Tests execution of a test which is configured to execute only methods with special tags, two classes specified | |||
| */ | |||
| @Test | |||
| public void testMethodWithTagFileSetFork() throws Exception { | |||
| final String target = "test-method-with-tag-fileset-fork"; | |||
| final Path tracker = setupTrackerProperty(target); | |||
| buildRule.executeTarget(target); | |||
| Assert.assertTrue("testMethodIncludeTagisExecuted was expected to be run", wasTestRun(tracker, JupiterSampleTest.class.getName(), | |||
| "testMethodIncludeTagisExecuted")); | |||
| Assert.assertFalse("testMethodIncludeTagisNotExecuted was expected NOT to be run", wasTestRun(tracker, JupiterSampleTest.class.getName(), | |||
| "testMethodIncludeTagisNotExecuted")); | |||
| Assert.assertTrue("testMethodIncludeTagisExecutedTagSampleTest was expected to be run", wasTestRun(tracker, JupiterTagSampleTest.class.getName(), | |||
| "testMethodIncludeTagisExecutedTagSampleTest")); | |||
| Assert.assertFalse("testMethodIncludeTagisNotExecutedTagSampleTest was expected NOT to be run", wasTestRun(tracker, JupiterTagSampleTest.class.getName(), | |||
| "testMethodIncludeTagisNotExecutedTagSampleTest")); | |||
| Assert.assertFalse("testMethodIncludeTagisNotExecutedTagSampleTest2 was expected NOT to be run", wasTestRun(tracker, JupiterTagSampleTest.class.getName(), | |||
| "testMethodIncludeTagisNotExecutedTagSampleTest2")); | |||
| // Do it in the test, cause otherwise the file will be too big | |||
| Files.deleteIfExists(tracker); | |||
| } | |||
| private Path setupTrackerProperty(final String targetName) { | |||
| final String filename = targetName + "-tracker.txt"; | |||
| buildRule.getProject().setProperty(targetName + ".tracker", filename); | |||
| @@ -22,6 +22,7 @@ import org.junit.jupiter.api.AfterEach; | |||
| import org.junit.jupiter.api.BeforeAll; | |||
| import org.junit.jupiter.api.BeforeEach; | |||
| import org.junit.jupiter.api.Disabled; | |||
| import org.junit.jupiter.api.Tag; | |||
| import org.junit.jupiter.api.Test; | |||
| import static org.junit.jupiter.api.Assertions.fail; | |||
| @@ -57,6 +58,21 @@ public class JupiterSampleTest { | |||
| void testSkipped() { | |||
| } | |||
| @Test | |||
| @Tag("fast") | |||
| void testMethodIncludeTagisExecuted() { | |||
| } | |||
| @Test | |||
| @Tag("fast") | |||
| void testMethodIncludeTagisExecuted2() { | |||
| } | |||
| @Test | |||
| @Tag("slow") | |||
| void testMethodIncludeTagisNotExecuted() { | |||
| } | |||
| @AfterEach | |||
| void afterEach() { | |||
| } | |||
| @@ -0,0 +1,63 @@ | |||
| /* | |||
| * 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. | |||
| * | |||
| */ | |||
| package org.example.junitlauncher.jupiter; | |||
| import org.junit.jupiter.api.AfterAll; | |||
| import org.junit.jupiter.api.AfterEach; | |||
| import org.junit.jupiter.api.BeforeAll; | |||
| import org.junit.jupiter.api.BeforeEach; | |||
| import org.junit.jupiter.api.Tag; | |||
| import org.junit.jupiter.api.Test; | |||
| /** | |||
| * | |||
| */ | |||
| public class JupiterTagSampleTest { | |||
| @BeforeAll | |||
| static void beforeAll() { | |||
| } | |||
| @BeforeEach | |||
| void beforeEach() { | |||
| } | |||
| @Test | |||
| @Tag("fast") | |||
| void testMethodIncludeTagisExecutedTagSampleTest() { | |||
| } | |||
| @Test | |||
| @Tag("slow") | |||
| void testMethodIncludeTagisNotExecutedTagSampleTest() { | |||
| } | |||
| @Test | |||
| @Tag("extraSlow") | |||
| void testMethodIncludeTagisNotExecuted2TagSampleTest() { | |||
| } | |||
| @AfterEach | |||
| void afterEach() { | |||
| } | |||
| @AfterAll | |||
| static void afterAll() { | |||
| } | |||
| } | |||