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.
You can install this tool from the UI or from the command line.
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.
You can add the JUnit Executor as a standalone tool using the wizard.
(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:
String lastName = System.getProperty("lastName") |
(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:
String lastName = System.getProperty("lastName") |
Execution details and results will be reported in the Console view. Additionally, any test failures detected will be reported in the Quality Tasks view:
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:
Application.showMessage("this displays in 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.
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.
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.
To send the output data from your JUnit test to a tool that processes XML data:
In this example, we will store the values of the multiplyResult
and sumResult
JUnit operations in an XML Data Bank so that the values can be used in a subsequent test. The following procedure will occur:
@Test public void testExample() throws Exception { int multiplyResult = 8 * 8; int sumResult = 8 + 8; // Create map representing name-value pairs for XML Map<String, String> map = new HashMap<String, String>(); map.put("multiplyResult", String.valueOf(multiplyResult)); map.put("sumResult", String.valueOf(sumResult)); // Get the Parasoft Scripting Context ScriptingContext context = Application.getContext(); // Place the map in the context with the custom_tool_junit_output context.put("custom_tool_junit_output", map); } |
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.
Additional license details are available in this plugin's licenses folder.