Application of BeanShell in manual testing and management

Source: Internet
Author: User
Tags manual stub throwable

While JUnit unit testing has been deeply rooted, it has also found itself powerless to test user interaction:

TestCase allows testers to make dynamic changes

A test parameter input function (UI or parameter profile) can be implemented in test case to solve the problem, but the cost of implementing these features and the amount of duplication is significant.

TestCase can be reused, combined, and saved easily

Not all test environments allow you to open a heavyweight Java IDE to write code that has strict specifications. That's why scripting languages are popular.

BeanShell can solve the above problems better.

1.BeanShell Basic:

BSh. Interpreter is the main interface of BeanShell.

Here's how to implement a simple Java Shell:

public class TestInt {
public static void main(String[] args) {
bsh.Interpreter.main(args);
}
}

Results:

BeanShell 2.0b4-by Pat Niemeyer (pat@pat.net)

BSh% System.out.println ("Hello BeanShell");

Hello BeanShell

BSH%

You can also use the following code to achieve the same function, the code can be more obvious to see its structure:

public static void main(String[] args) {
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 );
i.run();//线程在这里阻塞读System.in
}

1.1.BeanShell context (Context/namespace):

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 );
Collection theObjectReadyForShellUser = new ArrayList();
theObjectReadyForShellUser.add("Str1");
i.set("myObject", theObjectReadyForShellUser);
i.run();
}

User's UI:

BeanShell 2.0b4-by Pat Niemeyer (pat@pat.net)

BSh% System.out.println (myobject.get (0));

Str1

BSH%

The shell's context is particularly useful in testing. Think about it, if the "Theobjectreadyforshelluser" above is replaced by a RMI local interface stub generated for the test user, the corresponding stub method is invoked by the test user. This can be applied to dynamic testing or to remote administration of the system.

1.2. Static Java code is used in combination with dynamic Java code.

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
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.