Testing with beanshell

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Testing with beanshell

Furash Gary
Message
I couldn't resist trying to script a Junit test with Beanshell.  I've almost got it but have this wierd behavior.  The script below works fine, but when executed beanshell somehow gets the exception that is normally caught internally by the junit framework.  So, it nicely prints out that my assert didn't work (good), but then beanshell dumps with a stack-trace (junit.framework.AssertionFailedError).  I tried catching and burying it which had the effect I thought it would - it runs, but reports no problems.
 
 
 
 
 
-------------------------------------
 
importCommands("gov.maricopa.mcao.beanshell.cmd.io");
import junit.framework.*;
 
class ScriptTest extends TestCase {
 
 bsh = null;
 bshOut = null;
 bshErr = null;
 
 //setUp() {
  //b.eval("sm();"); bshOut.reset(); b.eval("sm();"); bshOut.reset(); print(bshOut);
 //}
 
 public ScriptTest(String method) {
  super(method);
  super(method);
  bshOut = new ByteArrayOutputStream();
  bshErr = new ByteArrayOutputStream();
  bsh = new Interpreter(new StringReader(""), new PrintStream(bshOut),
     new PrintStream(bshErr), false, null);
//  b.eval(getFileContents("Script.bsh"));
 }
 
 public void testFirst() {
  i = 1;
  y = 2;
  super.assertEquals(i, y);
 }
 
 public static TestSuite suite() {
  return new TestSuite(ScriptTest.class);
 }
 

}
 
junit.textui.TestRunner.run(ScriptTest.class);
 
Gary Furash, Applications Manager, Maricopa County Attorney's Office