How to Provide Testwise Coverage for Test Impact Analysis (TIA) and Pareto Optimization
To use the Test Impact Analysis or Pareto Optimization, you'll need to provide test coverage on a per-test basis to Teamscale with a testwise coverage report.
Teamscale combines the testwise coverage with the changes it reads from the version control system to determine which tests are impacted (Test Impact analysis). A test is impacted if it runs through the changed areas and therefore needs to be executed in the next test run. Teamscale can also determine which tests are redundant with each other with respect to coverage (Pareto testing).
On Impacted Tests
The impacted tests can miss tests that fail because of a change to files that are not executable code. Teamscale only considers changes to code that the testwise coverage tracks. For example, changes to resource or configuration files can influence a test, but they do not make it impacted. Therefore, also run all tests at regular intervals, for example, nightly.
Depending on the technologies you use, select the right approach to record testwise coverage:
If you use a different technology or an unsupported test runner, use the generic approach or reach out. If you are building your own, refer to our API documentation in your Teamscale installation (located in the (?) menu > API Reference > sub-section Test Intelligence) to implement the integration yourself.
Generic Approach with teamscale-build
This approach works for all technologies.
- You instrument your tests with a supported coverage profiler.
- You run each of your tests separately, gather test coverage for only that one test. You end up with many test coverage reports, one per test case.
- You use
teamscale-buildto combine these report files into one testwise coverage report. - You upload the testwise coverage report with
teamscale-upload.
Java Virtual Machine (JVM)
Our Java profiler can record testwise coverage. For tests that are run by Maven or Gradle, we provide plugins that automate both testwise coverage collection and smart test execution with Test Impact analysis.
For other tests, you can use our profiler directly and send events via its REST API when tests start and end.
Gradle
Our Teamscale Gradle plugin can be used with JUnit Platform-based tests. It adds additional options to your Test tasks that allow you to:
- Collect Testwise Coverage for your tests
- Only run impacted tests
- Sort your test execution to fail fast
Additionally, the plugin provides utilities to aggregate and upload test execution results and coverage from your build to Teamscale.
Tutorial
We also have a Tutorial on how to set up Test Impact Analysis in a Gradle-based Java project.
Maven and JUnit 5
If you use JUnit 5 (or any test framework built on JUnit 5, e.g., Serenity) for your tests, you can use our teamscale-maven-plugin to easily run TIA in your builds. It configures Surefire and Failsafe, so they fetch the list of impacted tests from Teamscale, execute them, and record and upload Testwise Coverage. This also works for Spring Boot applications.
We recommend that for regular, fast feedback, you run only impacted tests for most of your builds. It is, however, necessary to also run all tests from time to time (e.g., in a nightly or weekly build). This allows Teamscale to regularly update Testwise Coverage information for all tests. To achieve this, you can use Maven profiles and enable the teamscale-maven-plugin only in a special profile.
<profiles>
<profile>
<id>tia</id>
<activation>
<property>
<name>tia</name>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.teamscale</groupId>
<artifactId>impacted-test-engine</artifactId>
<version>34.2.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.teamscale</groupId>
<artifactId>teamscale-maven-plugin</artifactId>
<version>34.2.2</version>
<executions>
<execution>
<goals>
<goal>prepare-tia-unit-test</goal> <!-- Enables TIA for Surefire unit tests -->
<goal>prepare-tia-integration-test
</goal> <!-- Enables TIA for Failsafe integration tests -->
</goals>
</execution>
</executions>
<configuration>
<teamscaleUrl>http://localhost:8080</teamscaleUrl>
<projectId>teamscale-project-id</projectId>
<username>build</username>
<accessToken>${env.TEAMSCALE_ACCESS_TOKEN}</accessToken>
<includes>
<include>com.your.company.*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>List of All Available Parameters
To list all available parameters run mvn com.teamscale:teamscale-maven-plugin:help -Ddetail=true (also works without a maven project).
This adds the plugin and configures the connection to Teamscale. We recommend you also set at least one include pattern so coverage is only recorded for your code, not for 3rd party libraries.
It also configures Surefire and Failsafe to use our impacted-test-engine. This engine automatically fetches impacted tests from Teamscale and executes them. Make sure the engine version matches the teamscale-maven-plugin version.
Parallel Tests Not Supported
Parallelized tests are not supported by this plugin. When tests run in parallel, it is impossible to record Testwise Coverage as the coverage from the tests running in parallel cannot be distinguished anymore. Make sure to set <forkCount>1</forkCount> and <threadCount>1</threadCount> (c.f. the Maven documentation) for all tests where you enable the provider, otherwise a TIA-enabled build will fail. These settings are the defaults for Surefire and Failsafe.
Use of <reuseForks>false</reuseForks>
It is strongly encouraged to set <reuseForks>true</reuseForks>. Setting it to false will start and close a new JVM for each test case. Since the Teamscale-Maven-Plugin writes a coverage report every time the JVM closes, this can lead to performance problems on some systems.
The plugin sets the right system property to attach itself to Surefire and Failsafe tests. Surefire and Failsafe pick up the system property automatically and apply it to any JVMs they spawn.
Spring Boot
The plugin also works out-of-the-box for Spring Boot applications. Here, the Spring Boot Maven plugin will pick up the JVM options and pass them to the Spring Boot application that is started before the integration tests.
In some cases, your system-under-test is not launched by these plugins but by some other means (e.g., another plugin). In this case, make sure the argLine property is passed to the JVM of your system-under-test. If you do not want Surefire or Failsafe to pick up the argLine automatically or want to add additional parameters, you can change the name of the property that holds the JVM arguments by setting the configuration property <propertyName>.
If you need to add additional parameters to the Teamscale Java Profiler, you can use <additionalAgentOptions>.
Troubleshooting
For troubleshooting help, please have a look at the troubleshooting section of our Maven Plugin page.
Checking the Uploaded Testwise Coverage
Once you upload testwise coverage, Teamscale shows it in three places:
- The Code view and the method history show the tests that cover a method.
- The test details view shows the coverage and the results of a single test.
- The Delta perspective shows the impacted tests for a time range.
They help you verify that the upload works and find out which tests execute which code.
Determining Tests Covering a Method
After the initial testwise coverage upload, the Code view shows an indicator for each method that a test covered:

Click View method history to open the method history. Its Executed by tab lists all the tests that execute the method:

Viewing Detailed Test Information
You can open the test details view of a single test from the links in that dialog. You can also select the test in the Tests view of the Metrics perspective. The test details view shows the most recent test execution result at the top. The treemap below it shows the coverage of this single test on the whole codebase. The Show only executed methods option focuses the treemap on the executed code regions. At the bottom, the view shows the 10 previous test executions with their durations and results. Click one of them to open the test details view for that execution, for example, to inspect the error message of a previous failure.

Determining Impacted Tests over Large Time Intervals
The Delta perspective lists the impacted tests for a time range or a merge scenario that you select:

The list requires a testwise coverage report uploaded for a timestamp before the end of the selected time range.
Use this list to verify that Teamscale computes impacted tests correctly. You can also use it to support manual test selection.
