In this section:
The JUnit Executor tool enables you to execute JUnit tests in conjunction with the various other types of tests you can run with SOAtest. This enables you to design and execute a single test scenario that orchestrates JUnit tests as part of a broader sequence of events, such as setting up a test environment or test data, running unit tests via this tool, then executing mobile tests.
- JUnit 3.8.x and 4 are supported
- This tool requires SOAtest 9.8.1 or later
You can install this tool from the UI or from the command line.
- Choose Parasoft> Preferences from the main menu.
- Choose the Syster Properties tab and click Add JARs.
- Brows for the junitexecutor.jar file and click Apply.
- Restart SOAtest.
Command Line Installation
Add the junitexecutor.jar file to the
system.properties.classpath property in your settings.properties file. For example:
system.properties.classpath=<path to jar>/junitexecutor.jar
The test's class folder or jar file must contain the JUnit that you want executed. Other dependencies can be included in the jar/folder, added to the system properties, or both. The tool checks the jar/folder first, then the system properties if necessary.
Adding the Tool
You can add the JUnit Executor as a standalone tool using the wizard.
- Right-click on a Test Suite folder and choose Add New> Test...
- Browse for the JUnit Executor tool and click Finish.
- Configure the tool according to your scenario.
Running a Specific Test Method
- Specify the test's class folder or jar file, as well as the test class and test method you want to run.
(Optional) If you want to dynamically change JUnit values from this tool, enter the desired key-value pairs, separated by a semicolon, in the Data field.
These variables can be accessed from within your JUnit source code using Java's System Properties object, for example:
Running all Test Methods in a Class
- Specify the test's class folder or jar file, as well as the test class. Leave the Method field empty.
(Optional) If you want to dynamically change JUnit values from this tool, enter the desired key-value pairs, separated by a semicolon, in the Data field. These variables can be accessed from within your JUnit source code using Java's System Properties object, for example:
Execution details and results will be reported in the Console view. Additionally, any test failures detected will be reported in the Quality Tasks view:
Reporting Messages from JUnit Test to Console
Import the com.parasoft.api package into your project to access the Application Context, which enables SOAtest to report messages from your JUnit test execution to the console:
Add <SOATEST_INSTALL>/plugins/com.parasoft.ptest.libs.web_<version>/root/com.parasoft.api.jar to your Java project classpath to import the resource.
Retrieving Data from a JUnit Test
You can attach a SOAtest output to the JUnit Executor to retrieve data from your JUnit test output so that the data can be used in other tests. You need to configure the JUnit to indicate which values you want stored, and then attach an appropriate tool to the JUnit Output of the executor tool. The data will be passed to the attached tool in XML format. For example, you could send the data to a Diff tool, XML Assertor, or XML Data Bank tool.
Configuring the JUnit Output
Your JUnit must access the application context and store the desired values in a standard Java Map under the
custom_tool_junit_output key. The JUnit Executor tool will check the application context for the stored map and convert it to XML that gets passed to the tool's "JUnit Output" output. The map's keys and values must be strings.
Import the com.parasoft.api package into your JUnit as described in Reporting Messages from JUnit Test to Console to access the Application Context.
Sending the Data to Another Tool
To send the output data from your JUnit test to a tool that processes XML data:
- Right-click the JUnit Executor and choose Add Output.
- Choose a tool for receiving the output and click Finish.
In this example, we will store the values of the
sumResult JUnit operations in an XML Data Bank so that the values can be used in a subsequent test. The following procedure will occur:
- The JUnit test constructs a map containing the values
- The map is placed into the application context.
- The values in the map will be converted into an XML document that is passed to any tools attached to the JUnit Output
Add a JUnit Executor tool configured to run this test and add an XML Data Bank tool to the JUnit output.
Specify which values to extract and use in other tools. The content of the map appears below the
<root> element within the XML document that is passed to the tools attached to the JUnit output. In this example, a value assertion tool was added.
This plug-in includes items that have been sourced from third parties as outlined below.
- JUnit (Eclipse Public License 1.0)
Additional license details are available in this plugin's licenses folder.