This is an automated email from the ASF dual-hosted git repository. jaikiran pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ant.git
The following commit(s) were added to refs/heads/master by this push: new b845192 [junitlauncher] Add support for selecting tests based on JUnit-5 tag functionality b845192 is described below commit b8451922b6f3293d221c3718fa867b6d3a9278de Author: Matthias Gutheil <matthias.guth...@gmail.com> AuthorDate: Tue May 21 15:44:39 2019 +0200 [junitlauncher] Add support for selecting tests based on JUnit-5 tag functionality This closes #93 pull request at github/apache/ant repo --- CONTRIBUTORS | 1 + WHATSNEW | 7 ++ contributors.xml | 4 + manual/Tasks/junitlauncher.html | 14 +++ .../testcases/taskdefs/optional/junitlauncher.xml | 65 +++++++++++++ .../optional/junitlauncher/LauncherSupport.java | 9 ++ .../optional/junitlauncher/StandaloneLauncher.java | 32 +++++++ .../optional/junitlauncher/confined/Constants.java | 2 + .../junitlauncher/confined/JUnitLauncherTask.java | 55 +++++++++++ .../junitlauncher/confined/LaunchDefinition.java | 11 +++ .../junitlauncher/JUnitLauncherTaskTest.java | 105 ++++++++++++++++++++- .../junitlauncher/jupiter/JupiterSampleTest.java | 16 ++++ ...erSampleTest.java => JupiterTagSampleTest.java} | 22 ++--- 13 files changed, 329 insertions(+), 14 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index bb8e063..c269a67 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -281,6 +281,7 @@ Matthew Warman Matthew Watson Matthew Yanos Matthias Bhend +Matthias Gutheil Michael Bayne Michael Clarke Michael Davey diff --git a/WHATSNEW b/WHATSNEW index 7b5d45f..722bc07 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -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 ===================================== diff --git a/contributors.xml b/contributors.xml index 602e7b1..dad2dc9 100644 --- a/contributors.xml +++ b/contributors.xml @@ -1168,6 +1168,10 @@ <last>Bhend</last> </name> <name> + <first>Matthias</first> + <last>Gutheil</last> + </name> + <name> <first>Michael</first> <last>Bayne</last> </name> diff --git a/manual/Tasks/junitlauncher.html b/manual/Tasks/junitlauncher.html index 60ece58..7875c49 100644 --- a/manual/Tasks/junitlauncher.html +++ b/manual/Tasks/junitlauncher.html @@ -130,6 +130,20 @@ <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 the tests. JUnit 4+ classifies failures as both assertion failures as well as exceptions diff --git a/src/etc/testcases/taskdefs/optional/junitlauncher.xml b/src/etc/testcases/taskdefs/optional/junitlauncher.xml index 6204369..e33f031 100644 --- a/src/etc/testcases/taskdefs/optional/junitlauncher.xml +++ b/src/etc/testcases/taskdefs/optional/junitlauncher.xml @@ -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> diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java index 1155d09..2f17224 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java @@ -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 { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/StandaloneLauncher.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/StandaloneLauncher.java index 090e8f1..ea41c29 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/StandaloneLauncher.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/StandaloneLauncher.java @@ -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; + } } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/Constants.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/Constants.java index 53bc0dc..18c552c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/Constants.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/Constants.java @@ -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"; diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/JUnitLauncherTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/JUnitLauncherTask.java index 654211e..c880ffa 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/JUnitLauncherTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/JUnitLauncherTask.java @@ -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); @@ -360,6 +405,16 @@ public class JUnitLauncherTask extends Task { } @Override + public List<String> getIncludeTags() { + return includeTags; + } + + @Override + public List<String> getExcludeTags() { + return excludeTags; + } + + @Override public ClassLoader getClassLoader() { return this.executionCL; } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/LaunchDefinition.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/LaunchDefinition.java index 10e7f4d..38afe1d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/LaunchDefinition.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/LaunchDefinition.java @@ -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(); } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java index 6530836..32ca3c2 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java @@ -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); diff --git a/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTest.java b/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTest.java index b11286b..f0b678f 100644 --- a/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTest.java +++ b/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTest.java @@ -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() { } diff --git a/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTest.java b/src/tests/junit/org/example/junitlauncher/jupiter/JupiterTagSampleTest.java similarity index 72% copy from src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTest.java copy to src/tests/junit/org/example/junitlauncher/jupiter/JupiterTagSampleTest.java index b11286b..60d6724 100644 --- a/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTest.java +++ b/src/tests/junit/org/example/junitlauncher/jupiter/JupiterTagSampleTest.java @@ -21,17 +21,13 @@ 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.Disabled; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.fail; - /** * */ -public class JupiterSampleTest { - - private static final String message = "The quick brown fox jumps over the lazy dog"; +public class JupiterTagSampleTest { @BeforeAll static void beforeAll() { @@ -42,21 +38,21 @@ public class JupiterSampleTest { } @Test - void testSucceeds() { - System.out.println(message); - System.out.print("<some-other-message>Hello world! <!-- some comment --></some-other-message>"); + @Tag("fast") + void testMethodIncludeTagisExecutedTagSampleTest() { } @Test - void testFails() { - fail("intentionally failing"); + @Tag("slow") + void testMethodIncludeTagisNotExecutedTagSampleTest() { } @Test - @Disabled("intentionally skipped") - void testSkipped() { + @Tag("extraSlow") + void testMethodIncludeTagisNotExecuted2TagSampleTest() { } + @AfterEach void afterEach() { }