woolfel 2005/09/19 07:22:43 Modified: src/junit/org/apache/jmeter/protocol/java/sampler Tag: rel-2-1 JUnitSampler.java Log: fixed a bug with setUp/tearDown being called twice. This was because I changed the sampler to call run(TestResult), which calls setUp/tearDown. To fix that I finally figured out how to call the test method directly. Know it should work properly reporting assertion pass/fail and logging the results to the listener. peter Revision Changes Path No revision No revision 1.11.2.6 +24 -16 jakarta-jmeter/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java Index: JUnitSampler.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java,v retrieving revision 1.11.2.5 retrieving revision 1.11.2.6 diff -u -r1.11.2.5 -r1.11.2.6 --- JUnitSampler.java 13 Sep 2005 18:46:36 -0000 1.11.2.5 +++ JUnitSampler.java 19 Sep 2005 14:22:43 -0000 1.11.2.6 @@ -23,6 +23,7 @@ import java.util.Enumeration; import junit.framework.ComparisonFailure; +import junit.framework.Protectable; import junit.framework.TestCase; import junit.framework.TestResult; @@ -64,7 +65,6 @@ /// the Method objects for setUp and tearDown methods protected Method SETUP_METHOD = null; protected Method TDOWN_METHOD = null; - protected Method RUN_METHOD = null; protected boolean checkStartUpTearDown = false; protected TestCase TEST_INSTANCE = null; @@ -301,25 +301,28 @@ TestResult tr = new TestResult(); this.TEST_INSTANCE.setName(getMethod()); try { + if (!getDoNotSetUpTearDown() && SETUP_METHOD != null){ SETUP_METHOD.invoke(this.TEST_INSTANCE,new Class[0]); } - if (RUN_METHOD == null) { - RUN_METHOD = getRunTestMethod(this.TEST_INSTANCE); - } - Method m = getMethod(this.TEST_INSTANCE,getMethod()); + final Method m = getMethod(this.TEST_INSTANCE,getMethod()); + final TestCase theClazz = this.TEST_INSTANCE; + tr.startTest(this.TEST_INSTANCE); sresult.sampleStart(); - // use run method to run the test instead of the method directly - // we invoke TestCase.run(TestResult). If it happens to be null, - // we invoke the method directly, though that shouldn't happen - // unless the junit class breaks convention - if (RUN_METHOD != null) { - Object[] p = {tr}; - RUN_METHOD.invoke(this.TEST_INSTANCE,p); - } else { - m.invoke(this.TEST_INSTANCE,new Class[0]); - } + // Do not use TestCase.run(TestResult) method, since it will + // call setUp and tearDown. Doing that will result in calling + // the setUp and tearDown method twice and the elapsed time + // will include setup and teardown. + Protectable p = new Protectable() { + public void protect() throws Throwable { + m.invoke(theClazz,new Class[0]); + } + }; + tr.runProtected(theClazz, p); + // m.invoke(this.TEST_INSTANCE,new Class[0]); + tr.endTest(this.TEST_INSTANCE); sresult.sampleEnd(); + if (!getDoNotSetUpTearDown() && TDOWN_METHOD != null){ TDOWN_METHOD.invoke(TEST_INSTANCE,new Class[0]); } @@ -362,7 +365,12 @@ buf.append(getFailure()); Enumeration en = tr.errors(); while (en.hasMoreElements()){ - buf.append((String)en.nextElement()); + Object item = en.nextElement(); + if (item instanceof String) { + buf.append((String)en.nextElement()); + } else if (item instanceof Throwable) { + buf.append( ((Throwable)item).getMessage() ); + } } sresult.setResponseMessage(buf.toString()); sresult.setResponseCode(getFailureCode());
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]