In this section:
The test impact analysis (TIA) functionality analyzes the coverage data for the application under test and generates a list of tests that have been affected by changes since the previous build. The list of tests are saved to a .lst file that you can pass as a resource to the SOAtest command line interface. SOAtest will only the subset of tests affected identified by TIA in order to validate the changes. The following overview describes the test impact analysis process:
- Configuration: Configure the coverage agent (agent.jar) shipped with SOAtest, attach it to your AUT, and enable SOAtest to communicate with the agent.
- Collect information about what test cases cover: Run your full test suite so that the agent can collect data about the tests and the code they cover.
- Generate a baseline coverage report: Process the data collected by the agent to create a baseline report.
- Generate the .lst file containing the tests affected by changes: When a new version of the application is available, run the
TestImpactAnalysisscript to process the baseline coverage report. A .lst file containing the tests affected by change will be created.
- Run the tests affected by change: Deploy the latest version of the application (.war) to your server and run a job that executes SOAtest using the .lst file as the input to verify the changes.
TIA is intended to be implemented as part of an automated process. Perform the following steps to enable TIA.
Package your Application
Package your application under test into a deployable .war file.
Attaching the Coverage Agent to the AUT
SOAtest includes a Java agent that generates the coverage information necessary for SOAtest to determine which tests are affected by changes.
The agent is shipped in the <INSTALL>/test_impact_analysis/integration/coverage directory. It takes configuration settings from the agent.properties file in the same directory. You should copy the coverage directory that contains the agent.jar and agent.properties files to the machine where the AUT is running.
Configuring the Coverage Agent
Application servers usually contain more than one application. Additionally, common server classes or application libraries do not need to be instrumented. The agent only needs to collect coverage for application source code. Instrumenting all classes would be too time-consuming. For this reason, properly setting the scope of the coverage agent is very important.
You can configure the coverage agent by modifying the properties in the agent.properties and passing the properties to the
-javaagent argument. The agent supports several parameters (see Coverage Agent Parameters), but configuring the default settings is suitable for most cases:
Coverage Agent Parameters
The following table describes all properties that can be set for the agent:
|Enables/disables associating coverage with particular tests; the default value is |
|Specifies a location on the application server for the agent to store the coverage data it collects at runtime.|
A comma-separated list of patterns that specify classes to be instrumented. The following wildcards are supported:
In the following example, all classes from the
A comma-separated list of patterns that specify classes to be excluded from instrumentation. The following wildcards are supported:
In the following example, all classes from the
|Enables/disables automatic runtime data collection; the default is |
|Sets up agent communication port; the default is |
|Enables/disables verbose output to console; the default is |
|Enables/disables collecting coverage information for test cases; the default is |
Enables/disables collecting web application coverage for multiple users; the default is
|Activates the agent.|
|Enables the agent to collect coverage using the JaCoCo engine; the default is |
When the properties are configured, add a
-javaagent argument when starting your application server to attach the agent and include the agent configuration file:
For your convenience, the coverage directory includes a script that will generate the
-javaagent arguments. Run either the agent.sh or agent.bat script and copy the output to your server startup script.
In the following example, the agent is attached to a Tomcat server with a JAVA_OPTS variable at the beginning of the catalina.sh (Linux) or catalina.bat (Windows) scripts:
Start the application and verify that the agent is ready by opening
<host>:8050/status in your browser. You should see a JSON object that contains test, runtime_coverage, and testCase properties, e.g.:
You can also check the directory you specified with the runtimeData property (
/home/TIA/coverage_storage in the example above). The directory should contain a set of static coverage data files. The files are generated when the agent is started.
Creating the Test Configuration
You will need to create a test configuration in SOAtest that reports test execution information to the coverage agent. The test configuration only needs to be created once.
- Choose Parasoft> Test Configurations from the SOAtest menu and expand the Builtin category.
- Right-click Demo Configuration and choose Duplicate.
- Specify a new name for the configuration (i.e., TIA_agent) and click the Execution tab.
- Click the Application Coverage tab and specify the host name or IP address where the application under test and coverage agent are hosted and the port number of the agent. The port number should match the value of the
jtest.agent.portsetting in the agent.properties file (default is
- Click Test Connection to verify that SOAtest can communicate with the agent.
- (Optional) Under Coverage agent user ID, you can specify a user ID so that coverage results can be associated with a specific user. A user ID should only be specified when the
jtest.agent.enableMultiuserCoverageproperty is set to
truein the agent.properties file. We recommend specifying agent user IDs when multiple users or automated test runs are configured to access the same instance of the AUT at the same time. This is so that their interactions do not affect the correlation between tests and code covered for other users.
- If you want test failures reported when the coverage agent connection fails, enable the Report coverage agent connection failures as test failures option. Otherwise connection problems will be reported to the console, but will not cause the test to fail.
- Enable the Retrieve coverage data option and specify a directory in which to locally store the runtime coverage data. The data saved to this directory is analyzed to generate the baseline coverage report.
- Click Apply to save your changes.
Collecting Test and Coverage Data
Run your full test suite using the new test configuration. If you already have an automated test run, you can modify the existing job to use the new test configuration, e.g.:
See Testing from the Command Line Interface - soatestcli for details about building test execution commands with SOAtest. You can also manually run tests from the SOAtest GUI.
Generating Baseline Coverage
SOAtest includes a script for creating the baseline coverage report. The script analyzes the coverage data collected by the full test run and the WAR file for the AUT to generate the report. Depending on your operating system, you can run either the TestImpactAnalysis.bat (Windows) or TestImpactAnalysis.sh (Linux/macOS) script located in the <INSTALL>/test_impact_analysis directory.
TEMP Directory for Linux/MacOS
You may need to modify the .sh script and specify a temporary directory if the variable is not already set, e.g.:
When the test finishes, run the TestImpactAnalysis.sh or TestImpactAnalysis.bat script using the following syntax to generate the coverage report.
-appflag specifies the deployable .war. You should specify the same artifact deployed as the AUT for the automated test run (see Package your Application).
-runtimeCoverageflag specifies the directory you configured in the test configuration.
-outputReportflag is optional and specifies where to output the coverage report.
-includeflag is optional and specifies a space-separated list of patterns to include in the analysis. By default, all test classes are included.
-excludeflag is optional and specifies a space-separated list of patterns to exclude in the analysis. Classes that match patterns specified with the
-includeflag override excluded patterns.
- Add the
-keepRuntimeCoverageoption if you want to keep the runtime coverage data files used to generate the baseline coverage XML report. This This parameter does not take a value and is primarily used for debugging purposes. If it is not included in the command, the runtime coverage data files will be removed at the end of the execution.
When the script finishes, the coverage.xml report will be saved to the location specified with the
-outputReport flag. If the flag is not included, the file will be saved to the <USER_HOME>/parasoft/test_impact_analysis/reports/ directory by default.
Generating List of Tests Affected by Change
When a new version of the application is available, run the TestImpactAnalysis.sh or TestImpactAnalysis.bat script using the following syntax:
-appflag specifies the new deployable .war (see Package your Application).
-coverageReportflag should specify the coverage.xml report generated in Generating Baseline Coverage.
-outputLstflag is optional and specifies where to output the results.
When the script finishes, the result will be saved to a .lst file in the directory specified with the
-outputLst flag. If the flag is not included, the file will be saved to the <USER_HOME>/parasoft/test_impact_analysis/lsts/ directory by default. The default name of the .lst file will be
<yyyyMMdd_HHmmss>_affected_tests.lst. The .lst file will only be generated if tests are affected by the changes.
Executing Tests Affected by Change
To execute only the tests reported by TIA, specify the .lst file during SOAtest execution with the
See Testing from the Command Line Interface - soatestcli for details about building test execution commands with SOAtest.