You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by rg...@apache.org on 2015/05/03 19:57:50 UTC

svn commit: r1677461 - in /zookeeper/branches/branch-3.5: CHANGES.txt src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java

Author: rgs
Date: Sun May  3 17:57:49 2015
New Revision: 1677461

URL: http://svn.apache.org/r1677461
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.5/CHANGES.txt
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java

Modified: zookeeper/branches/branch-3.5/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/CHANGES.txt?rev=1677461&r1=1677460&r2=1677461&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.5/CHANGES.txt Sun May  3 17:57:49 2015
@@ -80,6 +80,10 @@ BUGFIXES:
   ZOOKEEPER-2173. ZK startup failure should be handled with proper error message
   (J.Andreina via camille)
 
+  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-1660 Documentation for Dynamic Reconfiguration (Reed Wanderman-Milne via shralex)
 

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java?rev=1677461&r1=1677460&r2=1677461&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java Sun May  3 17:57:49 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 static 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);
         }
     }