zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject svn commit: r1677463 - in /zookeeper/branches/branch-3.4: CHANGES.txt src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java
Date Sun, 03 May 2015 18:02:51 GMT
Author: rgs
Date: Sun May  3 18:02:51 2015
New Revision: 1677463

URL: http://svn.apache.org/r1677463
Log:
ZOOKEEPER-2174 JUnit4ZKTestRunner logs test failure for all exceptions

JUnit4ZKTestRunner logs test failure for all exceptions, even if the test
method is annotated with an expected exception (Chris Nauroth via rgs).

Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1677463&r1=1677462&r2=1677463&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Sun May  3 18:02:51 2015
@@ -70,6 +70,10 @@ BUGFIXES:
   ZOOKEEPER-2056 Zookeeper 3.4.x and 3.5.0-alpha is not OSGi compliant
   (Deiwin Sarjas via rgs)
 
+  ZOOKEEPER-2174 JUnit4ZKTestRunner logs test failure for all exceptions even
+  if the test method is annotated with an expected exception (Chris Nauroth
+  via rgs)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1575. adding .gitattributes to prevent CRLF and LF mismatches for

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java?rev=1677463&r1=1677462&r2=1677463&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java
Sun May  3 18:02:51 2015
@@ -20,6 +20,7 @@ package org.apache.zookeeper;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.junit.Test;
 import org.junit.internal.runners.statements.InvokeMethod;
 import org.junit.runners.BlockJUnit4ClassRunner;
 import org.junit.runners.model.FrameworkMethod;
@@ -38,16 +39,18 @@ public class JUnit4ZKTestRunner extends
     }
 
     public class LoggedInvokeMethod extends InvokeMethod {
-        private String name;
+        private final FrameworkMethod method;
+        private final String name;
 
         public LoggedInvokeMethod(FrameworkMethod method, Object target) {
             super(method, target);
+            this.method = method;
             name = method.getName();
         }
 
         @Override
         public void evaluate() throws Throwable {
-            LOG.info("RUNNING TEST METHOD " + name);
+            LOG.info("RUNNING TEST METHOD {}", name);
             try {
                 super.evaluate();
                 Runtime rt = Runtime.getRuntime();
@@ -59,10 +62,20 @@ public class JUnit4ZKTestRunner extends
                 }
                 LOG.info("Number of threads {}", tg.activeCount());
             } catch (Throwable t) {
-                LOG.info("TEST METHOD FAILED " + name, t);
+                // The test method threw an exception, but it might be an
+                // expected exception as defined in the @Test annotation.
+                // Check the annotation and log an appropriate message.
+                Test annotation = this.method.getAnnotation(Test.class);
+                if (annotation != null && annotation.expected() != null &&
+                        annotation.expected().isAssignableFrom(t.getClass())) {
+                    LOG.info("TEST METHOD {} THREW EXPECTED EXCEPTION {}", name,
+                        annotation.expected());
+                } else {
+                    LOG.info("TEST METHOD FAILED {}", name, t);
+                }
                 throw t;
             }
-            LOG.info("FINISHED TEST METHOD " + name);
+            LOG.info("FINISHED TEST METHOD {}", name);
         }
     }
 



Mime
View raw message