You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2009/09/23 16:51:00 UTC

svn commit: r818127 - /jakarta/jmeter/trunk/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java

Author: sebb
Date: Wed Sep 23 14:51:00 2009
New Revision: 818127

URL: http://svn.apache.org/viewvc?rev=818127&view=rev
Log:
Better handling of JUnit4 exceptions - convert to JUnit3 failures so they don't appear as errors.
Only store basic item details in responseMessage - trace details are saved in responseData

Modified:
    jakarta/jmeter/trunk/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java

Modified: jakarta/jmeter/trunk/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java?rev=818127&r1=818126&r2=818127&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java (original)
+++ jakarta/jmeter/trunk/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java Wed Sep 23 14:51:00 2009
@@ -387,10 +387,16 @@
             } catch (InvocationTargetException e) {
                 Throwable cause = e.getCause();
                 if (cause instanceof AssertionFailedError){
-                    log.warn("AFE:"+cause.toString());
-                    tr.addFailure(theClazz, (AssertionFailedError) cause);                        
+                    tr.addFailure(theClazz, (AssertionFailedError) cause);
+                } else if (cause instanceof AssertionError) {
+                    // Convert JUnit4 failure to Junit3 style
+                    AssertionFailedError afe = new AssertionFailedError(cause.toString());
+                    // copy the original stack trace
+                    afe.setStackTrace(cause.getStackTrace());
+                    tr.addFailure(theClazz, afe);
+                } else if (cause != null) {
+                    tr.addError(theClazz, cause);                        
                 } else {
-                    log.warn("ANY:"+e.toString()+" "+cause);
                     tr.addError(theClazz, e);                        
                 }
             } catch (IllegalAccessException e) {
@@ -401,6 +407,7 @@
             if ( !tr.wasSuccessful() ){
                 sresult.setSuccessful(false);
                 StringBuffer buf = new StringBuffer();
+                StringBuffer buftrace = new StringBuffer();
                 Enumeration<TestFailure> en;
                 if (getAppendError()) {
                     en = tr.failures();
@@ -411,11 +418,14 @@
                     }
                     while (en.hasMoreElements()){
                         TestFailure item = en.nextElement();
-                        buf.append( "Trace -- ");
-                        buf.append( item.trace() );
                         buf.append( "Failure -- ");
                         buf.append( item.toString() );
                         buf.append("\n");
+                        buftrace.append( "Failure -- ");
+                        buftrace.append( item.toString() );
+                        buftrace.append("\n");
+                        buftrace.append( "Trace -- ");
+                        buftrace.append( item.trace() );
                     }
                     en = tr.errors();
                     if (en.hasMoreElements()){
@@ -425,14 +435,18 @@
                     }
                     while (en.hasMoreElements()){
                         TestFailure item = en.nextElement();
-                        buf.append( "Trace -- ");
-                        buf.append( item.trace() );
                         buf.append( "Error -- ");
                         buf.append( item.toString() );
                         buf.append("\n");
+                        buftrace.append( "Error -- ");
+                        buftrace.append( item.toString() );
+                        buftrace.append("\n");
+                        buftrace.append( "Trace -- ");
+                        buftrace.append( item.trace() );
                     }
                 }
                 sresult.setResponseMessage(buf.toString());
+                sresult.setResponseData(buftrace.toString(), null);
             }
         } else {
             // we should log a warning, but allow the test to keep running
@@ -579,6 +593,14 @@
                     throw e;
                 }
                 if (expectedException == None.class){
+                    // Convert JUnit4 AssertionError failures to JUnit3 style so
+                    // will be treated as failure rather than error.
+                    if (thrown instanceof AssertionError && !(thrown instanceof AssertionFailedError)){
+                        AssertionFailedError afe = new AssertionFailedError(thrown.toString());
+                        // copy the original stack trace
+                        afe.setStackTrace(thrown.getStackTrace());
+                        throw afe;
+                    }
                     throw thrown;                    
                 }
                 if (!expectedException.isAssignableFrom(thrown.getClass())){



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org