[testng] 122/160: Add use case for #739
Eugene Zhukov
eugene-guest at moszumanska.debian.org
Tue Aug 18 10:22:29 UTC 2015
This is an automated email from the git hooks/post-receive script.
eugene-guest pushed a commit to annotated tag testng-6.9.5
in repository testng.
commit 2983e999d9d986b6a83da8e7705379314bc2035c
Author: Julien Herr <julien.herr at alcatel-lucent.com>
Date: Wed Jun 24 23:59:25 2015 +0200
Add use case for #739
---
src/test/java/test/InvokedMethodNameListener.java | 30 +++++++++++++++++++++-
src/test/java/test/inheritance/testng739/A.java | 17 ++++++++++++
src/test/java/test/inheritance/testng739/B.java | 10 ++++++++
.../java/test/inheritance/testng739/BaseClass.java | 9 +++++++
.../java/test/inheritance/testng739/TestNG739.java | 26 +++++++++++++++++++
src/test/resources/testng.xml | 1 +
6 files changed, 92 insertions(+), 1 deletion(-)
diff --git a/src/test/java/test/InvokedMethodNameListener.java b/src/test/java/test/InvokedMethodNameListener.java
index 69e70e3..25f56f7 100644
--- a/src/test/java/test/InvokedMethodNameListener.java
+++ b/src/test/java/test/InvokedMethodNameListener.java
@@ -8,9 +8,13 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+// TODO replace other test IInvokedMethodListener by this one
public class InvokedMethodNameListener implements IInvokedMethodListener {
private final List<String> invokedMethodNames = new ArrayList<>();
+ private final List<String> failedMethodNames = new ArrayList<>();
+ private final List<String> skippedMethodNames = new ArrayList<>();
+ private final List<String> succeedMethodNames = new ArrayList<>();
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
@@ -18,9 +22,33 @@ public class InvokedMethodNameListener implements IInvokedMethodListener {
}
@Override
- public void afterInvocation(IInvokedMethod method, ITestResult testResult) { }
+ public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
+ switch (testResult.getStatus()) {
+ case ITestResult.FAILURE:
+ failedMethodNames.add(method.getTestMethod().getConstructorOrMethod().getName());
+ break;
+ case ITestResult.SKIP:
+ skippedMethodNames.add(method.getTestMethod().getConstructorOrMethod().getName());
+ break;
+ case ITestResult.SUCCESS:
+ succeedMethodNames.add(method.getTestMethod().getConstructorOrMethod().getName());
+ break;
+ }
+ }
public List<String> getInvokedMethodNames() {
return Collections.unmodifiableList(invokedMethodNames);
}
+
+ public List<String> getFailedMethodNames() {
+ return failedMethodNames;
+ }
+
+ public List<String> getSkippedMethodNames() {
+ return skippedMethodNames;
+ }
+
+ public List<String> getSucceedMethodNames() {
+ return succeedMethodNames;
+ }
}
diff --git a/src/test/java/test/inheritance/testng739/A.java b/src/test/java/test/inheritance/testng739/A.java
new file mode 100644
index 0000000..cb84ce4
--- /dev/null
+++ b/src/test/java/test/inheritance/testng739/A.java
@@ -0,0 +1,17 @@
+package test.inheritance.testng739;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class A extends BaseClass {
+
+ @BeforeClass
+ public void beforeClassA() {
+ Assert.fail();
+ }
+
+ @Test
+ public void testA() {
+ }
+}
diff --git a/src/test/java/test/inheritance/testng739/B.java b/src/test/java/test/inheritance/testng739/B.java
new file mode 100644
index 0000000..ede5fde
--- /dev/null
+++ b/src/test/java/test/inheritance/testng739/B.java
@@ -0,0 +1,10 @@
+package test.inheritance.testng739;
+
+import org.testng.annotations.Test;
+
+public class B extends BaseClass {
+
+ @Test
+ public void testB() {
+ }
+}
diff --git a/src/test/java/test/inheritance/testng739/BaseClass.java b/src/test/java/test/inheritance/testng739/BaseClass.java
new file mode 100644
index 0000000..8186cac
--- /dev/null
+++ b/src/test/java/test/inheritance/testng739/BaseClass.java
@@ -0,0 +1,9 @@
+package test.inheritance.testng739;
+
+import org.testng.annotations.BeforeClass;
+
+public class BaseClass {
+
+ @BeforeClass
+ public void beforeBaseClass() {}
+}
diff --git a/src/test/java/test/inheritance/testng739/TestNG739.java b/src/test/java/test/inheritance/testng739/TestNG739.java
new file mode 100644
index 0000000..f837e51
--- /dev/null
+++ b/src/test/java/test/inheritance/testng739/TestNG739.java
@@ -0,0 +1,26 @@
+package test.inheritance.testng739;
+
+import org.testng.TestNG;
+import org.testng.annotations.Test;
+
+import test.InvokedMethodNameListener;
+import test.SimpleBaseTest;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class TestNG739 extends SimpleBaseTest {
+
+ @Test
+ public void test_classes_should_be_skipped_when_a_before_class_fails() {
+ TestNG tng = create(A.class, B.class);
+ tng.setPreserveOrder(true);
+ InvokedMethodNameListener listener = new InvokedMethodNameListener();
+ tng.setPreserveOrder(true);
+ tng.addListener(listener);
+
+ tng.run();
+ assertThat(listener.getSucceedMethodNames()).containsExactly("beforeBaseClass", "beforeBaseClass", "testB");
+ assertThat(listener.getFailedMethodNames()).containsExactly("beforeClassA");
+ assertThat(listener.getSkippedMethodNames()).containsExactly("testA");
+ }
+}
diff --git a/src/test/resources/testng.xml b/src/test/resources/testng.xml
index aa276f3..f1d9016 100644
--- a/src/test/resources/testng.xml
+++ b/src/test/resources/testng.xml
@@ -221,6 +221,7 @@
<classes>
<class name="test.SampleInheritance" />
<class name="test.inheritance.ClassScopeTest" />
+ <class name="test.inheritance.testng739.TestNG739"/>
</classes>
</test>
--
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