1、BeanShell上下文(Context/Namespace)
Reader in = new InputStreamReader( System.in );
PrintStream out = System.out;
PrintStream err = System.err;
boolean interactive = true;;
bsh.Interpreter i = new Interpreter( in, out, err, interactive );
Collection theObjectReadyForShellUser = new ArrayList();
theObjectReadyForShellUser.add("Str1");
i.set("myObject", theObjectReadyForShellUser);
i.run();
}
用户的UI:
bsh % System.out.println( myObject.get(0) );
Str1
bsh %
Shell的上下文在测试中特别有用。想一下,如果将上面的“theObjectReadyForShellUser”换成一个预先为测试用户生成的RMI本地接口存根,由测试用户调用相应的存根方法。这可应用于动态测试,也可以应用于系统的远程管理。
2、静态Java代码与动态Java代码的组合使用
public static void main(String[] args) throws Throwable {Reader in = new InputStreamReader( System.in );
PrintStream out = System.out;
PrintStream err = System.err;
boolean interactive = true;;
bsh.Interpreter i = new Interpreter( in, out, err, interactive );
//show a dialog for user to input command.
String command = JOptionPane.showInputDialog( "Input Command(s)" );
i.eval( command );//Run the command
}
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/