Class JUnitTestRunner

All Implemented Interfaces:
Generator, Renamable, ResourceProvider

public class JUnitTestRunner extends AbstractGenerator

A Generator for TestResults using the JUnit platform. The runner assumes that it is configured as Generator for a test project. The class path for running the tests is build as follows:

  1. Request compilation classpath resources from the test project's dependencies with Intent.Consume, Intent.Expose, and Intent.Supply. This makes the resources available that are used for compiling test classes as well as the compiled test classes.

  2. If the project implements MergedTestProject, get the Project.parentProject(), request compilation class path resources from its dependencies with Intent.Consume, Intent.Expose, and Intent.Supply and add them to the class path. This makes the resources available that are used for compiling the classes under test as well as the classes under test. Note that this is partially redundant, because test projects most likely have a dependency with Intent.Consume on the project under test anyway in order to compile the test classes. This dependency does not, however, provide all resources that are required to test the project under test.

The runner then requests all resources of type ClassTree from the test projects's Generator's and passes them to JUnit's test class detector.

Libraries for compiling the tests and a test engine of your choice must be provided explicitly to the runner's project as dependencies, e.g. as:

project.dependency(Consume, new MvnRepoLookup()
    .bom("org.junit:junit-bom:5.12.2")
    .resolve("org.junit.jupiter:junit-jupiter-api")
    .resolve(Scope.Runtime,
       "org.junit.jupiter:junit-jupiter-engine"));

In order to track the execution of the each test, you can enable level fine logging for this class. Level finer will also provide information about the class paths.

  • Constructor Details

    • JUnitTestRunner

      public JUnitTestRunner(Project project)
      Initializes a new test runner.
      Parameters:
      project - the project
  • Method Details

    • ignoreFailed

      Ignore failed tests. If invoked, the test runner does not set the faulty flag of the test results if a test has failed.
      Returns:
      the junit test runner
    • syncOn

      public JUnitTestRunner syncOn(Object syncObject)

      By default, JUnitTestRunners run independently of each other. Because they run in the VM, this can cause concurrency issues if components in different test projects share static resources.

      By invoking this method, JUnitTestRunners with the same syncObject are synchronized, i.e. run in sequence.

      Parameters:
      syncObject - the sync object
      Returns:
      the j unit test runner
    • doProvide

      protected <T extends Resource> Stream<T> doProvide(ResourceRequest<T> requested)
      Description copied from class: AbstractProvider
      Invoked by ResourceProviderSpi.provide(ResourceRequest) after checking if the invocation is allowed.
      Specified by:
      doProvide in class AbstractProvider
      Type Parameters:
      T - the generic type
      Parameters:
      requested - the request for resources
      Returns:
      the stream