[testng] 136/355: Initial commit for reporting JUnit Parameterized tests
Eugene Zhukov
eugene-guest at moszumanska.debian.org
Tue Aug 18 10:19:57 UTC 2015
This is an automated email from the git hooks/post-receive script.
eugene-guest pushed a commit to annotated tag OpenBSD
in repository testng.
commit 10749d45726849381f4ff7384ef7154cec5299d4
Author: jdillet <jdillet at ada>
Date: Sun Jan 25 19:34:13 2015 +0200
Initial commit for reporting JUnit Parameterized tests
---
.../java/org/testng/internal/BaseTestMethod.java | 8 +--
.../org/testng/internal/ConfigurationMethod.java | 2 +-
.../java/org/testng/internal/FactoryMethod.java | 2 +-
.../java/org/testng/internal/TestNGMethod.java | 2 +-
.../java/org/testng/junit/JUnit4TestMethod.java | 6 ++-
.../java/org/testng/junit/JUnitTestMethod.java | 6 ++-
src/test/java/test/JUnit4Test.java | 16 ++++++
.../java/test/junit4/JUnit4ParameterizedTest.java | 57 ++++++++++++++++++++++
8 files changed, 90 insertions(+), 9 deletions(-)
diff --git a/src/main/java/org/testng/internal/BaseTestMethod.java b/src/main/java/org/testng/internal/BaseTestMethod.java
index 5257ebd..e0ded14 100755
--- a/src/main/java/org/testng/internal/BaseTestMethod.java
+++ b/src/main/java/org/testng/internal/BaseTestMethod.java
@@ -82,15 +82,15 @@ public abstract class BaseTestMethod implements ITestNGMethod {
* @param annotationFinder
* @param instance
*/
- public BaseTestMethod(Method method, IAnnotationFinder annotationFinder, Object instance) {
- this(new ConstructorOrMethod(method), annotationFinder, instance);
+ public BaseTestMethod(String methodName, Method method, IAnnotationFinder annotationFinder, Object instance) {
+ this(methodName, new ConstructorOrMethod(method), annotationFinder, instance);
}
- public BaseTestMethod(ConstructorOrMethod com, IAnnotationFinder annotationFinder,
+ public BaseTestMethod(String methodName, ConstructorOrMethod com, IAnnotationFinder annotationFinder,
Object instance) {
m_methodClass = com.getDeclaringClass();
m_method = com;
- m_methodName = com.getName();
+ m_methodName = methodName;
m_annotationFinder = annotationFinder;
m_instance = instance;
m_signature = computeSignature();
diff --git a/src/main/java/org/testng/internal/ConfigurationMethod.java b/src/main/java/org/testng/internal/ConfigurationMethod.java
index 7003939..2c84bcd 100755
--- a/src/main/java/org/testng/internal/ConfigurationMethod.java
+++ b/src/main/java/org/testng/internal/ConfigurationMethod.java
@@ -59,7 +59,7 @@ public class ConfigurationMethod extends BaseTestMethod {
boolean initialize,
Object instance)
{
- super(com, annotationFinder, instance);
+ super(com.getName(), com, annotationFinder, instance);
if(initialize) {
init();
}
diff --git a/src/main/java/org/testng/internal/FactoryMethod.java b/src/main/java/org/testng/internal/FactoryMethod.java
index c990aad..dc5e2e5 100644
--- a/src/main/java/org/testng/internal/FactoryMethod.java
+++ b/src/main/java/org/testng/internal/FactoryMethod.java
@@ -36,7 +36,7 @@ public class FactoryMethod extends BaseTestMethod {
IAnnotationFinder annotationFinder,
ITestContext testContext)
{
- super(com, annotationFinder, instance);
+ super(com.getName(), com, annotationFinder, instance);
// Utils.checkInstanceOrStatic(instance, method);
Class<?> declaringClass = com.getDeclaringClass();
if (instance != null && ! declaringClass.isAssignableFrom(instance.getClass())) {
diff --git a/src/main/java/org/testng/internal/TestNGMethod.java b/src/main/java/org/testng/internal/TestNGMethod.java
index 3cd92bc..d364696 100755
--- a/src/main/java/org/testng/internal/TestNGMethod.java
+++ b/src/main/java/org/testng/internal/TestNGMethod.java
@@ -43,7 +43,7 @@ public class TestNGMethod extends BaseTestMethod implements Serializable {
private TestNGMethod(Method method, IAnnotationFinder finder, boolean initialize,
XmlTest xmlTest, Object instance) {
- super(method, finder, instance);
+ super(method.getName(), method, finder, instance);
if(initialize) {
init(xmlTest);
diff --git a/src/main/java/org/testng/junit/JUnit4TestMethod.java b/src/main/java/org/testng/junit/JUnit4TestMethod.java
index 77ddf6a..e5cc38e 100644
--- a/src/main/java/org/testng/junit/JUnit4TestMethod.java
+++ b/src/main/java/org/testng/junit/JUnit4TestMethod.java
@@ -11,7 +11,7 @@ import org.testng.internal.Utils;
public class JUnit4TestMethod extends JUnitTestMethod {
public JUnit4TestMethod(JUnitTestClass owner, Description desc) {
- super(owner, getMethod(desc), desc);
+ super(owner, desc.getMethodName(), getMethod(desc), desc);
}
@Override
@@ -22,6 +22,10 @@ public class JUnit4TestMethod extends JUnitTestMethod {
private static Method getMethod(Description desc) {
Class<?> c = desc.getTestClass();
String method = desc.getMethodName();
+ int idx = method.indexOf('[');
+ if (idx != -1) {
+ method = method.substring(0, idx);
+ }
try {
return c.getMethod(method);
} catch (Throwable t) {
diff --git a/src/main/java/org/testng/junit/JUnitTestMethod.java b/src/main/java/org/testng/junit/JUnitTestMethod.java
index 2ee0e7a..91ee459 100644
--- a/src/main/java/org/testng/junit/JUnitTestMethod.java
+++ b/src/main/java/org/testng/junit/JUnitTestMethod.java
@@ -12,7 +12,11 @@ import org.testng.internal.BaseTestMethod;
public abstract class JUnitTestMethod extends BaseTestMethod {
protected JUnitTestMethod(JUnitTestClass owner, Method method, Object instance) {
- super(method, null, instance);
+ this(owner, method.getName(), method, instance);
+ }
+
+ protected JUnitTestMethod(JUnitTestClass owner, String methodName, Method method, Object instance) {
+ super(methodName, method, null, instance);
setTestClass(owner);
owner.getTestMethodList().add(this);
}
diff --git a/src/test/java/test/JUnit4Test.java b/src/test/java/test/JUnit4Test.java
index 98b1f72..d9d9f27 100644
--- a/src/test/java/test/JUnit4Test.java
+++ b/src/test/java/test/JUnit4Test.java
@@ -3,6 +3,7 @@ package test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import test.junit4.JUnit4Child;
+import test.junit4.JUnit4ParameterizedTest;
import test.junit4.JUnit4Sample2;
import test.junit4.JUnit4SampleSuite;
@@ -77,4 +78,19 @@ public class JUnit4Test extends BaseTest {
verifyTests("Failed", failed, getFailedTests());
verifyTests("Skipped", skipped, getSkippedTests());
}
+
+ @Test
+ public void testTestParameterized() {
+ addClass("test.junit4.JUnit4ParameterizedTest");
+ assert getTest().isJUnit();
+
+ run();
+ String[] passed = JUnit4ParameterizedTest.EXPECTED;
+ String[] failed = JUnit4ParameterizedTest.FAILED;
+ String[] skipped = JUnit4ParameterizedTest.SKIPPED;
+
+ verifyTests("Passed", passed, getPassedTests());
+ verifyTests("Failed", failed, getFailedTests());
+ verifyTests("Skipped", skipped, getSkippedTests());
+ }
}
diff --git a/src/test/java/test/junit4/JUnit4ParameterizedTest.java b/src/test/java/test/junit4/JUnit4ParameterizedTest.java
new file mode 100644
index 0000000..fa35a24
--- /dev/null
+++ b/src/test/java/test/junit4/JUnit4ParameterizedTest.java
@@ -0,0 +1,57 @@
+package test.junit4;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+ at RunWith(Parameterized.class)
+public class JUnit4ParameterizedTest {
+
+ public static final String[] EXPECTED = {"t2[0]", "t2[1]", "t4[0]"};
+ public static final String[] SKIPPED = {"t3[0]", "t3[1]", "ta[0]", "ta[1]"};
+ public static final String[] FAILED = {"t4[1]", "tf[0]", "tf[1]"};
+
+ private int param;
+
+ @Parameters
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {{1}, {5}});
+ }
+
+ public JUnit4ParameterizedTest(int param) {
+ this.param = param;
+ }
+
+ @Test
+ public void t2() {
+ }
+
+ @Test
+ @Ignore
+ public void t3() {
+ }
+
+ @Test
+ public void t4() {
+ if (param == 5) {
+ Assert.fail("a test");
+ }
+ }
+
+ @Test
+ public void tf() {
+ Assert.fail("a test");
+ }
+
+ @Test
+ public void ta() {
+ Assume.assumeTrue(false);
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git
More information about the pkg-java-commits
mailing list