This topic explains how to generate JUnit tests that represent the actions recorded in a web browser.

Sections include:

About JUnit Test Generation

SOAtest can generate JUnit tests that represent a new or previously-recorded web scenario. You can set up a functional test against a Web application, then use the generated JUnit test cases to validate test results using the JUnit framework. This gives you the flexibility of a test script and the easy-to-use interface of SOAtest—without having to learn a new test scripting language.

The resulting class files are JUnit based and depend on the following jar files.

From <Parasoft Test install dir>/plugins/com.parasoft.xtest.libs_<version>:

From <Parasoft Test install dir>/plugins/com.parasoft.xtest.libs_<version>/Parasoft:

From <Parasoft Test install dir>/plugins/com.parasoft.xtest.libs.base_<version>:

From <Parasoft Test install dir>/plugins/com.parasoft.xtest.libs.base_<version>/Parasoft:

From <Parasoft SOAtest install dir>/eclipse/plugins/com.parasoft.xtest.libs.web_<version>/root/lib-java-mod:

From <Parasoft SOAtest install dir>/eclipse/plugins/com.parasoft.xtest.libs.web_<version>/root:

From <Parasoft SOAtest install dir>/eclipse/plugins/com.parasoft.xtest.license.eclipse.core.web_<version>/lib:


Before you start generating JUnit tests, perform this one-time configuration:

  1. Switch to the Java perspective (choose Window> Open Perspective> Other> Java).
  2. Create a new project in the workspace and name it MyJUnitTest.
  3. In the Package Explorer, right-click the new MyJUnitTest project, then choose Properties from the shortcut menu.
  4. Select Java Build Path, then go to the Libraries tab and click Add External JARs.
    1. Add to the build path of the project ALL jar files that live in <Parasoft Test install dir>/plugins/com.parasoft.xtest.libs_<version>.
    2. Add to the build path of the project ALL jar files that live in <Parasoft Test install dir>/plugins/com.parasoft.xtest.libs_<version>/Parasoft.
    3. Add to the build path of the project ALL jar files that live in <Parasoft Test install dir>/plugins/com.parasoft.xtest.libs.base_<version>.
    4. Add to the build path of the project ALL jar files that live in <Parasoft Test install dir>/plugins/com.parasoft.xtest.libs.base_<version>/Parasoft.
    5. Add to the build path of the project ALL jar files that live in <Parasoft SOAtest installation dir>/eclipse/plugins/com.parasoft.xtest.libs.web_<version>/root.
    6. Add to the build path of the project ALL jar files that live in /eclipse/plugins/com.parasoft.xtest.license.eclipse.core.web_<version>/lib.
  5. From the Java Build Path> Libraries tab:
    1. Click Add Library.
    2. Select JUnit, then click Next.
    3. Ensure that the JUnit library version is set to JUnit 4, then click Finish.

Generating JUnit Tests from a Scenario as You Record It

To generate JUnit tests from a scenario as you record it:

  1. Return to the SOAtest perspective.
  2. Open the pull-down menu for the New toolbar button (top left), choose Other, select SOAtest> Web> JUnit test from Web Browser Recording, then click Next.

  3. Complete the Record and Generate JUnit Test wizard page as follows:
  4. Click the Finish button. The designated start page will open in the selected browser.
  5. Specify the functionality that you want to capture by following it in the browser(s). You can click links, complete and submit forms, use the navigation bar to enter open URLs, access shortcuts, go forward or back, and so on.

    To ensure that recording works properly, you must wait until the page has fully loaded before performing some action.  You must wait each time the page or some part of the page gets reloaded before performing an action.

To complete forms, enter the values directly into the GUI controls as if you were actually navigating the site. For instance, type in your user name and password, select radio buttons, check or clear check boxes, and so on.

As you record sessions, please note:

  • Password recall and auto-completion in Internet Explorer’s (Internet Options Advanced settings) are not supported during recording.
  • Google Toolbar's Auto Fill feature is not supported.
  • A "type" test may not be recorded if you type the beginning of a term into a field, but then click on a suggestion from a drop down.

     6. Close the browser window(s).

A JUnit test class will be added to the specified output location. A new project will not be created or added to the Test Case Explorer.

Generating JUnit Tests from a Previously-Recorded Scenario

To generate JUnit tests that represent a previously-recorded test scenario:

  1. Return to the SOAtest perspective.
  2. In the Test Case Explorer, right-click the web scenario that you want to generate JUnit tests for, then choose Generate JUnit Tests from the shortcut menu.
  3. Complete the Generation Options dialog, then click Finish. Available options are:

Many users find it convenient to put all tests into the same project. However, you may create multiple projects if you prefer.

Executing the Generated Tests

To execute the generated tests:

  1. Go to the Java perspective.
  2. Refresh the MyJUnitTest project. You should see a node representing the generated test.
  3. Right-click and choose Run As> JUnit Test.

You can also execute these tests from the command line as described in the JUnit documentation.

Configuring License Information for JUnit Test Execution

License information is required to run JUnit tests generated by SOAtest. The license information can be set in two ways:

Adding Assertion Statements to the Generated Tests

Each JUnit class generated by SOAtest consists of one test function that mimics the test sequence of a SOAtest test. Whenever the server returns a response, the test will make an assignment to the Response object declared within the test function. You should insert assertion statements after these assignments to validate that the response from the server is expected.

We have created comment blocks where we recommend assertion placements within the test function.

For example:

public void testA() throws Exception {
	WebConversation wc = new WebConversation();
	WebRequest req = new GetMethodWebRequest("http://mole/tests/"); 
	WebResponse resp = wc.getResponse(req);
	//Begin assertions
	//End assertions
	WebLink link = resp.getLinkWith("popup.html");;
	resp = wc.getCurrentPage();
	//Begin assertions
	//End assertions
	WebForm form = resp.getFormWithName("childrenForm"); 
	resp = form.submit();
	//Begin assertions
	//End assertions

In the above JUnit test function, the blocks appear each time that the WebResponse object was assigned with a new value.