Class UniqueIdTrackingListener

java.lang.Object
org.junit.platform.launcher.listeners.UniqueIdTrackingListener
All Implemented Interfaces:
TestExecutionListener

@API(status=EXPERIMENTAL, since="1.8") public class UniqueIdTrackingListener extends Object implements TestExecutionListener
UniqueIdTrackingListener is a TestExecutionListener that tracks the unique IDs of all tests that were executed during the execution of the TestPlan and generates a file containing the unique IDs once execution of the TestPlan has finished.

Tests are tracked regardless of their TestExecutionResult or whether they were skipped, and the unique IDs are written to an output file, one ID per line, encoding using UTF-8.

The output file can be used to execute the same set of tests again without having to query the user configuration for the test plan and without having to perform test discovery again. This can be useful for test environments such as within a native image — for example, a GraalVM native image — in order to rerun the exact same tests from a standard JVM test run within a native image.

Configuration and Defaults

The OUTPUT_DIR is the directory in which this listener generates the output file. The exact path of the generated file is OUTPUT_DIR/OUTPUT_FILE_PREFIX-<random number>.txt, where <random number> is a pseudo-random number. The inclusion of a random number in the file name ensures that multiple concurrently executing test plans do not overwrite each other's results.

The value of the OUTPUT_FILE_PREFIX defaults to DEFAULT_OUTPUT_FILE_PREFIX, but a custom prefix can be set via the OUTPUT_FILE_PREFIX_PROPERTY_NAME configuration property.

The OUTPUT_DIR can be set to a custom directory via the OUTPUT_DIR_PROPERTY_NAME configuration property. Otherwise the following algorithm is used to select a default output directory.

  • If the current working directory of the Java process contains a file named pom.xml, the output directory will be ./target, following the conventions of Maven.
  • If the current working directory of the Java process contains a file with the extension .gradle or .gradle.kts, the output directory will be ./build, following the conventions of Gradle.
  • Otherwise, the current working directory of the Java process will be used as the output directory.

For example, in a project using Gradle as the build tool, the file generated by this listener would be ./build/junit-platform-unique-ids-<random number>.txt by default.

Configuration properties can be set via JVM system properties, via a junit-platform.properties file in the root of the classpath, or as JUnit Platform configuration parameters.

Since:
1.8
  • Field Details

    • LISTENER_ENABLED_PROPERTY_NAME

      public static final String LISTENER_ENABLED_PROPERTY_NAME
      Property name used to enable the UniqueIdTrackingListener: "junit.platform.listeners.uid.tracking.enabled"

      The UniqueIdTrackingListener is registered automatically via Java's ServiceLoader mechanism but disabled by default.

      Set the value of this property to true to enable this listener.

      See Also:
    • OUTPUT_DIR_PROPERTY_NAME

      public static final String OUTPUT_DIR_PROPERTY_NAME
      Property name used to set the path to the output directory for the file generated by the UniqueIdTrackingListener: "junit.platform.listeners.uid.tracking.output.dir"

      For details on the default output directory, see the class-level Javadoc.

      See Also:
    • OUTPUT_FILE_PREFIX_PROPERTY_NAME

      public static final String OUTPUT_FILE_PREFIX_PROPERTY_NAME
      Property name used to set the prefix for the name of the file generated by the UniqueIdTrackingListener: "junit.platform.listeners.uid.tracking.output.file.prefix"

      Defaults to DEFAULT_OUTPUT_FILE_PREFIX.

      See Also:
    • DEFAULT_OUTPUT_FILE_PREFIX

      public static final String DEFAULT_OUTPUT_FILE_PREFIX
      The default prefix for the name of the file generated by the UniqueIdTrackingListener: "junit-platform-unique-ids"
      See Also:
  • Constructor Details

    • UniqueIdTrackingListener

      public UniqueIdTrackingListener()
  • Method Details