[testng] 71/355: AfterClass does not get executed when MethodInterceptor is involved.

Eugene Zhukov eugene-guest at moszumanska.debian.org
Tue Aug 18 10:19:49 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 5f8941a053222c26990214bdbef3bc79a10a4085
Author: Krishnan Mahadevan <Krishnan.mahadevan1978 at gmail.com>
Date:   Sat Jun 14 13:43:16 2014 +0530

    AfterClass does not get executed when MethodInterceptor
    is involved.
    
    The logic to invoke AfterClass was ignoring the output
    of MethodInterceptor (especially the ones that alter the
    size of the total test methods to be executed). This
    led to AfterClass methods not getting executed at all.
    Fixed this problem by ensuring that the classMethodMap
    object is updated to refer to the output of a method
    interceptor in a TestRunner.
---
 src/main/java/org/testng/ClassMethodMap.java | 4 +++-
 src/main/java/org/testng/TestRunner.java     | 5 ++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/testng/ClassMethodMap.java b/src/main/java/org/testng/ClassMethodMap.java
index 658bc50..f75b1a8 100755
--- a/src/main/java/org/testng/ClassMethodMap.java
+++ b/src/main/java/org/testng/ClassMethodMap.java
@@ -28,7 +28,9 @@ public class ClassMethodMap {
       // Only add to the class map methods that are included in the
       // method selector. We can pass a null context here since the selector
       // should already have been initialized
-      if (! xmlMethodSelector.includeMethod(null, m, true)) continue;
+      if (xmlMethodSelector != null){
+    	  if (! xmlMethodSelector.includeMethod(null, m, true)) continue;
+      }
 
       Object instance = m.getInstance();
       List<ITestNGMethod> l = m_classMap.get(instance);
diff --git a/src/main/java/org/testng/TestRunner.java b/src/main/java/org/testng/TestRunner.java
index a636c21..1f2936b 100644
--- a/src/main/java/org/testng/TestRunner.java
+++ b/src/main/java/org/testng/TestRunner.java
@@ -790,7 +790,10 @@ public class TestRunner
     for (IMethodInstance imi : resultInstances) {
       result.add(imi.getMethod());
     }
-
+    //Since an interceptor is involved, we would need to ensure that the ClassMethodMap object is in sync with the 
+    //output of the interceptor, else @AfterClass doesn't get executed at all when interceptors are involved.
+    //so let's update the current classMethodMap object with the list of methods obtained from the interceptor.
+    this.m_classMethodMap = new ClassMethodMap(result, null);
     return result.toArray(new ITestNGMethod[result.size()]);
   }
 

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