# How to Provide Testwise Coverage for Test Impact Analysis (TIA)

In order to use the Test Impact analysis, you'll need to upload testwise coverage.

# Report Format for Testwise Coverage

Testwise Coverage is a combined JSON-based report format that holds various test related data (see sample below). Its basis is a list of all tests that are available for execution as one unit (e.g. UI Tests). A test is identified by a unique string (uniformPath). The full list allows Teamscale to determine added and deleted tests. Each of the test entries can additionally contain execution information (duration, result, message), coverage information (paths) and additional test metadata (sourcePath, content). The following overview provides more details on each of the available fields:

uniformPathUnique name of the test case by using a path like hierarchical description, which can be shown in the UI.
contentIdentifies the content of the test specification. This can be used to indicate that the specification of a test has changed and therefore should be re-executed. The value can be an arbitrary string value e.g., a hash of the test specification or a revision number of the test.
durationThe time it took to execute the test in seconds.
resultDescribes the result of the test execution. Can be one of:
  • PASSED Test execution was successful.
  • IGNORED The test is currently marked as "do not execute" (e.g. JUnit @Ignore or @Disabled).
  • SKIPPED Caused by a failing assumption.
  • FAILURE Caused by a failing assertion.
  • ERROR Caused by an error during test execution (e.g., exception thrown).
Tests that did not pass previously are always selected for test execution.
messageError message and stacktrace or skip reason.
pathsThe covered lines grouped by source file and path.

# Sample File for Testwise Coverage

The following JSON sample file combines the necessary data described above.

{
  "tests": [
    {
      "uniformPath": "com/example/project/JUnit4Test/notExecutedTest()"
    },
    {
      "uniformPath": "com/example/project/JUnit4Test/systemTest()",
      "duration": 0.025,
      "result": "PASSED",
      "content": "43d743a8ef4389bc5",
      "paths": [
        {
          "path": "com/example/project",
          "files": [
            {
              "fileName": "Calculator.java",
              "coveredLines": "20-24,26,27,29"
            },
            {
              "fileName": "JUnit4Test.java",
              "coveredLines": "26-28"
            }
          ]
        }
      ]
    },
    {
      "uniformPath": "com/example/project/JUnit5Test/failedTest()",
      "duration": 0.045,
      "result": "ERROR",
      "message": "Some error"
    },
    {
      "uniformPath": "com/example/project/JUnit5Test/skippedTest()",
      "result": "SKIPPED"
    }
  ]
}

# TIA for the Java Virtual Machine (JVM)

For JVM-based languages there exists an extension to the JaCoCo coverage profiler, which can be instructed to generate Testwise Coverage.

For Gradle based builds with JUnit Platform based tests there also exists a Gradle plugin. The plugin configures the test execution to use a custom Test Engine which handles the communication with Teamscale and delegates the actual execution to existing Test Engines.