Page tree

Skip to end of metadata
Go to start of metadata

The jtest task should be applied and executed only for the root project. You do not need to build a project before running analysis, but we recommend compiling multi-module projects beforehand  by adding the build or assemble task to your command line, for example. Doing so enables Jtest to use artifacts from the local repository, reducing the amount of time necessary to test and analyze code.

Before you run analysis or collect coverage information with Gradle, ensure that the Jtest license is properly configured (see Setting the License).

Running Static Analysis

To perform static analysis on your code:

  1. Ensure that the Jtest Plugin for Gradle is set up (see Configuring the Jtest Plugin for Gradle).
  2. Execute the jtest task. Your command line may resemble the following:

    gradle jtest -I PATH/TO/JTEST/integration/gradle/init.gradle

    The Jtest Plugin for Gradle will collect the necessary build data in the .json file, and analyze your code depending on the test configuration you provided.

  3. Review the analysis results (see Reviewing Results).

(info) By default, test sources are excluded from analysis. To analyze test code, disable the excludeTestSources option; see Jtest Goals Reference for Gradle.

Executing Unit Tests

You can include unit test results in the Jtest report by running your tests with the jtest task, and the dedicated Unit Tests built-in test configuration:

  1. Ensure that the Jtest Plugin for Gradle is set up (Configuring the Jtest Plugin for Gradle).
  2. Execute Gradle tasks in the following order:
    - the test (or build) task to ensure that unit tests are executed
    - the jtest task
      Your command line may resemble the following:

    gradle clean test jtest -Djtest.config="builtin://Unit Tests"

Collecting Coverage for Unit Tests

You can collect coverage information during execution of unit tests by your tests with the jtest and jtest-agent tasks, and the dedicated Unit Tests built-in test configuration:

  1. Ensure that the Jtest Plugin for Gradle is set up (Configuring the Jtest Plugin for Gradle).
  2. Execute Gradle tasks in the following order:
    - the jtest-agent task
    - the test (or build) task to ensure that unit tests are executed
    - the jtest task
      Your command line may resemble the following:

    gradle clean jtest-agent test jtest -Djtest.config="builtin://Unit Tests"

(info) If your build script specifies JVM arguments, ensure they do not override other JVM arguments.

Collecting Application Coverage

Jtest's coverage agent allows you to collect coverage data during manual or automated tests performed on a running application. See Application Coverage for information about collecting application coverage with Jtest.

Test Impact Analysis

You can extend the capabilities of the Jtest Plugin for Gradle with test impact analysis. It allows you to you to identify and re-run only the tests that are affected by your changes, eliminating the time and effort required to execute a large number of unaffected tests. To perform test impact analysis of your project, you need to:

  1. Configure the test impact analysis plugin.
  2. Execute the affectedTests task.

(info) You don't need to modify the Gradle build script.

Prerequisites

  • Jtest 10.4.1 or higher
  • Gradle 3.3 or higher

Licensing

Test impact analysis requires customizing your Parasoft license settings. Ensure that the 'custom_edition' license with the 'Change Based Testing' and 'Automation' features is enabled in your jtest.properties file.

(info) Test impact analysis may require additional memory. We recommend increasing the memory allocated to the Gradle build.

(info) Jtest may not perform test impact analysis if your Gradle build script contains include patterns to include all tests.

(info) If you perform test impact analysis multiple times in same local environment, add the --no-daemon option to your command line.

Integrating with the Test Impact Analysis Plugin

The init.gradle script shipped with Jtest allows you to integrate the test impact analysis plugin with Gradle – without having to modify your Gradle build script. To integrate Gradle with the plugin, pass the location of the the init.gradle script with the -I option to your command line:

gradle affectedTests test -I PATH/TO/JTEST/integration/gradle/init.gradle

Configuring the Plugin

You can customize test impact analysis of your project in the build file or in the command line by configuring the properties of the test impact analysis plugin. At minimum, you must provide the paths to the following files that are generated by Jtest during execution:

  • coverage.xml  

  • report.xml

See Jtest Tasks Reference for Gradle for the complete list of available options.

In the build script

Specify the properties when declaring a configuration in the build script:

build.gradle
affectedTests {
    coverageFile = 'path/to/coverage.xml'
    testFile = 'path/to/report.xml'
    runFailingTests = false
    runModifiedTests = true
    jtestHome = 'path/to/jtest'
    settingsFiles = ['path/to/settings1.properties', 'path/to/settings2.properties']
}

In the Command Line

If you configure the plugin in the command line, pass the plugin properties with the -D switch. The properties must include the "parasoft" or "jtest" prefix (see Jtest Tasks Reference for Gradle). Your command line may resemble the following:

Command Line
gradle affectedTests test -I PATH/TO/JTEST/integration/gradle/init.gradle -Dparasoft.coverage.file="path/to/coverage.xml" -Dparasoft.test.file="path/to/report.xml" -Dparasoft.runFailingTests=false -Dparasoft.runModifiedTests=true -Djtest.home="path/to/jtest" -Djtest.settings="jtestcli.properties,newsettings.properties"

Configuring and Executing the affectedTestTask

You can execute the affectedTests task from the command line without any further configuration. Ensure it is executed before the test task. Your command line may resemble the following:

Command Line
gradle clean affectedTests test -I PATH/TO/JTEST/integration/gradle/init.gradle

Alternatively, you can:

  1. Configure execution the task in the build.gradle script:

    build.gradle
    test.dependsOn affectedTests
  2. Execute the the Gradle test task – the affectedTests task will be executed automatically:

    Command Line
    gradle test -I PATH/TO/JTEST/integration/gradle/init.gradle


  • No labels