[testng] 201/355: Add test case for issue #629

Eugene Zhukov eugene-guest at moszumanska.debian.org
Tue Aug 18 10:20:05 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 04b42234cdf2bdb747a3b2da4b0a1c4a5c65c268
Author: Julien Herr <julien.herr at alcatel-lucent.com>
Date:   Wed Apr 22 22:50:12 2015 +0200

    Add test case for issue #629
---
 .../InvokedMethodListenerTest.java                 | 41 +++++++++++++++++++-
 .../InvokedMethodNameListener.java                 | 45 ++++++++++++++++++++++
 2 files changed, 84 insertions(+), 2 deletions(-)

diff --git a/src/test/java/test/invokedmethodlistener/InvokedMethodListenerTest.java b/src/test/java/test/invokedmethodlistener/InvokedMethodListenerTest.java
index 66a1ac6..2fc9f2b 100644
--- a/src/test/java/test/invokedmethodlistener/InvokedMethodListenerTest.java
+++ b/src/test/java/test/invokedmethodlistener/InvokedMethodListenerTest.java
@@ -2,6 +2,7 @@ package test.invokedmethodlistener;
 
 import org.testng.Assert;
 import org.testng.IInvokedMethod;
+import org.testng.IInvokedMethodListener;
 import org.testng.ITestResult;
 import org.testng.TestNG;
 import org.testng.annotations.Test;
@@ -12,13 +13,15 @@ import java.util.List;
 
 public class InvokedMethodListenerTest extends SimpleBaseTest {
 
-  private void run(Class[] classes, MyListener l) {
+  private static void run(Class[] classes, IInvokedMethodListener l) {
     TestNG tng = create();
     tng.setTestClasses(classes);
 
     tng.addInvokedMethodListener(l);
     tng.run();
+  }
 
+  private static void assertMethodCount(MyListener l) {
     Assert.assertEquals(l.getBeforeCount(), 9);
     Assert.assertEquals(l.getAfterCount(), 9);
   }
@@ -26,13 +29,15 @@ public class InvokedMethodListenerTest extends SimpleBaseTest {
   @Test
   public void withSuccess() {
     MyListener l = new MyListener();
-    run(new Class[] { Success.class }, l);
+    run(new Class[]{Success.class}, l);
+    assertMethodCount(l);
   }
 
   @Test
   public void withFailure() {
     MyListener l = new MyListener();
     run(new Class[] { Failure.class }, l);
+    assertMethodCount(l);
     Assert.assertEquals(l.getSuiteStatus(), ITestResult.FAILURE);
     Assert.assertTrue(null != l.getSuiteThrowable());
     Assert.assertTrue(l.getSuiteThrowable().getClass() == RuntimeException.class);
@@ -73,4 +78,36 @@ public class InvokedMethodListenerTest extends SimpleBaseTest {
 
     Assert.assertTrue(l.isSuccess);
   }
+
+  @Test(description = "Invoked method does not recognize configuration method")
+  public void issue629_InvokedMethodDoesNotRecognizeConfigurationMethod() {
+    InvokedMethodNameListener l = new InvokedMethodNameListener();
+    run(new Class[]{Success.class}, l);
+
+    Assert.assertEquals(l.testMethods.size(), 1);
+    Assert.assertTrue(l.testMethods.contains("a"));
+
+    Assert.assertEquals(l.testMethodsFromTM.size(), 1);
+    Assert.assertTrue(l.testMethodsFromTM.contains("a"));
+
+    Assert.assertEquals(l.configurationMethods.size(), 8);
+    Assert.assertTrue(l.configurationMethods.contains("beforeMethod"));
+    Assert.assertTrue(l.configurationMethods.contains("afterMethod"));
+    Assert.assertTrue(l.configurationMethods.contains("beforeTest"));
+    Assert.assertTrue(l.configurationMethods.contains("afterTest"));
+    Assert.assertTrue(l.configurationMethods.contains("beforeClass"));
+    Assert.assertTrue(l.configurationMethods.contains("afterClass"));
+    Assert.assertTrue(l.configurationMethods.contains("beforeSuite"));
+    Assert.assertTrue(l.configurationMethods.contains("afterSuite"));
+
+    Assert.assertEquals(l.configurationMethodsFromTM.size(), 8);
+    Assert.assertTrue(l.configurationMethodsFromTM.contains("beforeMethod"));
+    Assert.assertTrue(l.configurationMethodsFromTM.contains("afterMethod"));
+    Assert.assertTrue(l.configurationMethodsFromTM.contains("beforeTest"));
+    Assert.assertTrue(l.configurationMethodsFromTM.contains("afterTest"));
+    Assert.assertTrue(l.configurationMethodsFromTM.contains("beforeClass"));
+    Assert.assertTrue(l.configurationMethodsFromTM.contains("afterClass"));
+    Assert.assertTrue(l.configurationMethodsFromTM.contains("beforeSuite"));
+    Assert.assertTrue(l.configurationMethodsFromTM.contains("afterSuite"));
+  }
 }
diff --git a/src/test/java/test/invokedmethodlistener/InvokedMethodNameListener.java b/src/test/java/test/invokedmethodlistener/InvokedMethodNameListener.java
new file mode 100644
index 0000000..be1df42
--- /dev/null
+++ b/src/test/java/test/invokedmethodlistener/InvokedMethodNameListener.java
@@ -0,0 +1,45 @@
+package test.invokedmethodlistener;
+
+import org.testng.IInvokedMethod;
+import org.testng.IInvokedMethodListener;
+import org.testng.ITestResult;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class InvokedMethodNameListener implements IInvokedMethodListener {
+
+  final Set<String> testMethods = new HashSet<>();
+  final Set<String> configurationMethods = new HashSet<>();
+  final Set<String> testMethodsFromTM = new HashSet<>();
+  final Set<String> configurationMethodsFromTM = new HashSet<>();
+
+  @Override
+  public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
+  }
+
+  @Override
+  public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
+    String methodName = method.getTestMethod().getMethodName();
+
+    if (method.isTestMethod()) {
+      testMethods.add(methodName);
+    }
+    if (method.isConfigurationMethod()) {
+      configurationMethods.add(methodName);
+    }
+    if (method.getTestMethod().isTest()) {
+      testMethodsFromTM.add(methodName);
+    }
+    if (method.getTestMethod().isBeforeMethodConfiguration() ||
+        method.getTestMethod().isAfterMethodConfiguration() ||
+        method.getTestMethod().isBeforeTestConfiguration() ||
+        method.getTestMethod().isAfterTestConfiguration() ||
+        method.getTestMethod().isBeforeClassConfiguration() ||
+        method.getTestMethod().isAfterClassConfiguration() ||
+        method.getTestMethod().isBeforeSuiteConfiguration() ||
+        method.getTestMethod().isAfterSuiteConfiguration()) {
+      configurationMethodsFromTM.add(methodName);
+    }
+  }
+}

-- 
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