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 9a6ffdd01 bz-64564 add an example of junit-jupiter ParameterizedTest
when using junitlauncher task
9a6ffdd01 is described below
commit 9a6ffdd011aec572a4fb489f5be1c560a4c5912e
Author: Jaikiran Pai <[email protected]>
AuthorDate: Sat Aug 12 15:59:48 2023 +0530
bz-64564 add an example of junit-jupiter ParameterizedTest when using
junitlauncher task
---
fetch.xml | 1 +
lib/libraries.properties | 2 ++
lib/optional/junit-3.8.2.jar | Bin 120640 -> 0 bytes
.../testcases/taskdefs/optional/junitlauncher.xml | 33 +++++++++++++++++++++
.../junitlauncher/JUnitLauncherTaskTest.java | 14 +++++++++
.../junitlauncher/jupiter/JupiterSampleTest.java | 22 +++++++++++++-
6 files changed, 71 insertions(+), 1 deletion(-)
diff --git a/fetch.xml b/fetch.xml
index 07fcf7f8e..dff5e18ce 100644
--- a/fetch.xml
+++ b/fetch.xml
@@ -247,6 +247,7 @@ Set -Ddest=LOCATION on the command line
description="load junit jupiter engine libraries (necessary only for
internal Ant project tests)"
depends="init">
<f2 project="org.junit.jupiter" archive="junit-jupiter-engine" />
+ <f2 project="org.junit.jupiter" archive="junit-jupiter-params" />
</target>
<target name="junit-engine-vintage"
diff --git a/lib/libraries.properties b/lib/libraries.properties
index 418de4282..34b3159c9 100644
--- a/lib/libraries.properties
+++ b/lib/libraries.properties
@@ -71,6 +71,8 @@ junit-platform-launcher.version=1.8.2
junit-vintage-engine.version=5.8.2
# Only used for internal tests in Ant project
junit-jupiter-engine.version=5.8.2
+# Only used for internal tests in Ant project
+junit-jupiter-params.version=5.8.2
jsch.version=0.1.55
jython.version=2.7.2
# log4j 1.2.15 requires JMS and a few other Sun jars that are not in the m2
repo
diff --git a/lib/optional/junit-3.8.2.jar b/lib/optional/junit-3.8.2.jar
deleted file mode 100644
index c8f711d05..000000000
Binary files a/lib/optional/junit-3.8.2.jar and /dev/null differ
diff --git a/src/etc/testcases/taskdefs/optional/junitlauncher.xml
b/src/etc/testcases/taskdefs/optional/junitlauncher.xml
index 1163dc23b..c6aed61c8 100644
--- a/src/etc/testcases/taskdefs/optional/junitlauncher.xml
+++ b/src/etc/testcases/taskdefs/optional/junitlauncher.xml
@@ -39,6 +39,7 @@
<fileset dir="../../../../../lib/optional">
<include name="junit-jupiter*.jar"/>
<include name="opentest4j*.jar"/>
+ <include name="apiguardian-api*"/> <!-- required for jupiter
ParameterizedTest -->
</fileset>
</path>
@@ -398,5 +399,37 @@
</test>
</junitlauncher>
</target>
+
+ <target name="test-jupiter-parameterized-test" depends="init">
+ <junitlauncher>
+ <classpath refid="junit.engine.jupiter.classpath"/>
+ <classpath>
+ <pathelement location="${build.classes.dir}"/>
+ </classpath>
+ <test name="org.example.junitlauncher.jupiter.JupiterSampleTest"
+ outputdir="${output.dir}">
+ <listener classname="org.example.junitlauncher.Tracker"
+ outputDir="${output.dir}"
+
resultFile="${test-jupiter-parameterized-test.tracker}"
+ if="test-jupiter-parameterized-test.tracker"/>
+ <fork>
+ <sysproperty
+
key="junitlauncher.test.run-jupiter-parameterized-tests"
+ value="true" />
+ </fork>
+ <listener type="legacy-xml"
+ resultFile="JupiterSampleTest-ParameterizedTests.xml"
+ useLegacyReportingName="false"
+ />
+ </test>
+ </junitlauncher>
+ <junitreport>
+ <fileset dir="${output.dir}">
+ <include name="JupiterSampleTest-ParameterizedTests.xml"/>
+ </fileset>
+ <report
todir="${output.dir}/JupiterSampleTest-ParameterizedTests/html/"/>
+ </junitreport>
+ </target>
+
</project>
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 f3938d48a..ab19d6435 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
@@ -498,6 +498,20 @@ public class JUnitLauncherTaskTest {
ForkedTest.class.getName(), "testSysProp"));
}
+ /**
+ * Tests that junitlauncher can be used with parameterized junit-jupiter
tests
+ */
+ @Test
+ public void testJupiterParameterizedTest() throws Exception {
+ final String targetName = "test-jupiter-parameterized-test";
+ final Path trackerFile = setupTrackerProperty(targetName);
+ buildRule.executeTarget(targetName);
+ Assert.assertTrue("JupiterSampleTest#testOddPasses was expected to
succeed", verifySuccess(trackerFile,
+ JupiterSampleTest.class.getName(), "testOddPasses"));
+ Assert.assertTrue("JupiterSampleTest#testEvenFails was expected to
fail", verifyFailed(trackerFile,
+ JupiterSampleTest.class.getName(), "testEvenFails"));
+ }
+
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 780351287..481bba110 100644
--- a/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTest.java
+++ b/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTest.java
@@ -19,12 +19,16 @@ package org.example.junitlauncher.jupiter;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assumptions;
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 org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.fail;
/**
@@ -73,6 +77,22 @@ public class JupiterSampleTest {
void testMethodIncludeTagisNotExecuted() {
}
+ @ParameterizedTest(name = "{displayName} asserting {0} is an even number")
+ @ValueSource(ints = {2, 4, 6, 7, 12})
+ void testEvenFails(final int val) {
+ final boolean shouldRun =
Boolean.getBoolean("junitlauncher.test.run-jupiter-parameterized-tests");
+ Assumptions.assumeTrue(shouldRun, "Skipping testEvenFails");
+ assertEquals(0, val % 2, val + " is not an even number");
+ }
+
+ @ParameterizedTest(name = "{displayName} asserting {0} is an odd number")
+ @ValueSource(ints = {1, 3, 9})
+ void testOddPasses(final int val) {
+ final boolean shouldRun =
Boolean.getBoolean("junitlauncher.test.run-jupiter-parameterized-tests");
+ Assumptions.assumeTrue(shouldRun, "Skipping testOddPasses");
+ assertNotEquals(0, val % 2, val + " is not an odd number");
+ }
+
@AfterEach
void afterEach() {
}