Version 1.0.0, built against JUnit 6.1.3. API reference: Javadoc.

Motivation

Comparison and oracle testing

Comparison testing runs the same test against several comparison subjects aka variants, such as

  • API implementations,

  • database backends,

  • a real server and its test double.

The suite defines a contract shared by all variants. Grouping results by behavior lets readers compare variants for each test and input.

Use cases include:

  • Compatible API implementations.

  • Products that support several database backends.

  • Test doubles that must behave like the real thing.

One of the subjects can be an oracle, a reference implementation that is known to be correct. Test-driven development against an oracle then has two steps:

  1. Write a test that passes against the oracle and fails against your implementation.

  2. Make it pass against both subjects.

Comparison subjects always form the innermost level of the test tree. Each argument set of a @ParameterizedTest becomes a container with one test per subject. Comparing two SearchTree implementations, BinarySearchTree and TreeSetSearchTree, produces a report like this:

containsAddedKey(int, SearchTree) 
├─ [1] key = -7 
│  ├─ BinarySearchTree 
│  └─ TreeSetSearchTree 
└─ [2] key = 42 
   ├─ BinarySearchTree 
   └─ TreeSetSearchTree  expected: <true> but was: <false>

Why existing Jupiter features were not enough

Details

Subjects as @ParameterizedTest arguments

The Cartesian product of inputs and subjects can be generated in a @MethodSource:

@ParameterizedTest
@MethodSource("keysAndTrees")   // (-7, Binary), (-7, TreeSet), (42, Binary), (42, TreeSet)
void containsAddedKey(int key, Supplier<SearchTree> trees) { ... }
containsAddedKey(int, Supplier) 
├─ [1] key = -7, trees = BinarySearchTree 
├─ [2] key = -7, trees = TreeSetSearchTree 
├─ [3] key = 42, trees = BinarySearchTree 
└─ [4] key = 42, trees = TreeSetSearchTree 
  • Flat results: readers scan n × m siblings to distinguish failures by input from failures by subject.

  • Manual composition: each test must combine inputs and subjects rather than use @ValueSource, @CsvSource, or other sources unchanged. Each test must also repeat the subject list.

  • Tests without inputs still require parameterization just to receive a subject.

  • No single place to declare subjects for a class or suite.

Subjects as @ParameterizedClass arguments

@ParameterizedClass
@MethodSource("trees")
class ImplementationsAsClassParameterTests {
    @Parameter Supplier<SearchTree> trees;
    @Test void sizeIsZero() { ... }
    @ParameterizedTest @ValueSource(ints = { -7, 42 }) void containsAddedKey(int key) { ... }
}
ImplementationsAsClassParameterTests 
├─ [1] trees = BinarySearchTree 
│  ├─ containsAddedKey(int) 
│  │  ├─ [1] key = -7 
│  │  └─ [2] key = 42 
│  └─ sizeIsZero() 
└─ [2] trees = TreeSetSearchTree 
   ├─ containsAddedKey(int) 
   │  ├─ [1] key = -7 
   │  └─ [2] key = 42 
   └─ sizeIsZero() 

This approach is close (and technically the most correct one for the comparison testing), but the hierarchy is inverted: subject → test → input scatters each behavior’s outcomes across subjects

A CI build matrix has the same reporting problem: results are separated by subject rather than grouped by test invocation.

Subjects from a second TestTemplateInvocationContextProvider

Registering another TestTemplateInvocationContextProvider alongside @ParameterizedTest chains the providers' invocation streams rather than multiplying them:

@ExtendWith(Trees.class)   // a TestTemplateInvocationContextProvider supplying SearchTree instances
class TwoInvocationProvidersTests {
   @ParameterizedTest @ValueSource(ints = { -7, 42 })
   void containsAddedKey(int key, SearchTree tree) { ... }
}
containsAddedKey(int, SearchTree) 
├─ [1] BinarySearchTree  No ParameterResolver registered for parameter [int key] ...
├─ [2] TreeSetSearchTree  No ParameterResolver registered for parameter [int key] ...
├─ [3] key = -7  No ParameterResolver registered for parameter [SearchTree tree] ...
└─ [4] key = 42  No ParameterResolver registered for parameter [SearchTree tree] ...

Each invocation receives either an input or a subject, never both. Invocations are leaves; no public extension point can add children beneath them.

Dynamic tests

A @TestFactory can build the required hierarchy using DynamicContainer and DynamicTest, but requires rewriting existing tests as factories. The goal is to preserve ordinary test methods.

What Elara does

Elara is a JUnit Platform TestEngine with the id elara. It discovers classes annotated with @ComparisonTest, generates a Jupiter test class for each of them at run time, lets the real Jupiter engine execute the generated class, and maps the results back onto the original methods. Ordinary @Test and @ParameterizedTest methods stay as they are; the only additions are one class annotation, one source class that lists the subjects, and an implementation parameter on each test method.

how_it_works runner Runner Selects tests discovery Discovery Builds the test tree runner->discovery generation Generation Creates nested tests discovery->generation jupiter Jupiter Runs selected variants generation->jupiter reporting Reporting Maps results to source jupiter->reporting

Example

A comparison class is an ordinary Jupiter class with one extra annotation and an implementation parameter on each test. The class below compares two SearchTree implementations, BinarySearchTree and TreeSetSearchTree, and combines a parameterized class, parameterized tests, a plain test, and a skipped variant. The enum of variants, the ComparisonSource that lists them, and the project’s own @Skip annotation are left out here; the later sections show how to write them.

@ComparisonTest(source = SearchTreeImplementations.class) (1)
@ParameterizedClass                                        (2)
@ValueSource(ints = { 10, 1000 })
class SearchTreeTest {
    @Parameter
    int keyRange;

    @Test                                                  (3)
    void sizeIsZero(SearchTree tree) {
        assertEquals(0, tree.size());
    }

    @ParameterizedTest                                     (4)
    @ValueSource(ints = { -7, 42 })
    @ComparisonArguments(1)
    void containsAddedKey(int key, SearchTree tree) {
        tree.add(key % keyRange);
        assertTrue(tree.contains(key % keyRange));
    }

    @ParameterizedTest                                     (5)
    @ValueSource(ints = { 1, 2 })
    @ComparisonArguments(1)
    void matchesTreeSet(int seed, SearchTree tree) {
        Random random = new Random(seed);
        TreeSet<Integer> expected = new TreeSet<>();
        for (int i = 0; i < 100; i++) {
            int key = random.nextInt(keyRange);
            assertEquals(expected.add(key), tree.add(key));
        }
        assertEquals(List.copyOf(expected), tree.toSortedList());
    }

    @Test
    @Skip(value = TREE_SET, description = "TreeSet rejects null keys") (6)
    void acceptsNullKey(SearchTree tree) {
        assertTrue(tree.add(null));
        assertTrue(tree.contains(null));
    }
}
1 The source names the variants and supplies the SearchTree parameter for each of them.
2 A parameterized class adds its level above the tests, as in plain Jupiter.
3 A plain test receives the implementation as its last parameter and runs once per variant.
4 A parameterized test declares with @ComparisonArguments how many leading parameters its argument source supplies; the implementation parameter follows them.
5 A seeded parameterized test compares each tree with a TreeSet oracle. It takes the place of a @RepeatedTest, which Elara does not run.
6 The project’s own @Skip, typed with the variant enum, disables one variant of one test and gives the reason.

The test tree of an actual run (ConsoleLauncher --details=tree; Jupiter orders the methods):

SearchTreeTest 
├─ [1] keyRange = 10 
│  ├─ containsAddedKey(int, SearchTree) 
│  │  ├─ [1] -7 
│  │  │  ├─ BinarySearchTree 
│  │  │  └─ TreeSetSearchTree 
│  │  └─ [2] 42 
│  │     ├─ BinarySearchTree 
│  │     └─ TreeSetSearchTree 
│  ├─ matchesTreeSet(int, SearchTree) 
│  │  ├─ [1] 1 
│  │  │  ├─ BinarySearchTree 
│  │  │  └─ TreeSetSearchTree 
│  │  └─ [2] 2 
│  │     ├─ BinarySearchTree 
│  │     └─ TreeSetSearchTree 
│  ├─ acceptsNullKey(SearchTree) 
│  │  ├─ BinarySearchTree 
│  │  └─ TreeSetSearchTree  TreeSet rejects null keys
│  └─ sizeIsZero(SearchTree) 
│     ├─ BinarySearchTree 
│     └─ TreeSetSearchTree 
└─ [2] keyRange = 1000 
   ├─ containsAddedKey(int, SearchTree) 
   │  ├─ [1] -7 
   │  │  ├─ BinarySearchTree 
   │  │  └─ TreeSetSearchTree 
   │  └─ [2] 42 
   │     ├─ BinarySearchTree 
   │     └─ TreeSetSearchTree 
   ├─ matchesTreeSet(int, SearchTree) 
   │  ├─ [1] 1 
   │  │  ├─ BinarySearchTree 
   │  │  └─ TreeSetSearchTree 
   │  └─ [2] 2 
   │     ├─ BinarySearchTree 
   │     └─ TreeSetSearchTree 
   ├─ acceptsNullKey(SearchTree) 
   │  ├─ BinarySearchTree 
   │  └─ TreeSetSearchTree  TreeSet rejects null keys
   └─ sizeIsZero(SearchTree) 
      ├─ BinarySearchTree 
      └─ TreeSetSearchTree 
  • @Test: test → variant.

  • @ParameterizedTest: test → arguments → variant.

  • @ParameterizedClass: adds its level above the test as usual, and the variants stay innermost.

  • A skipped variant stays in the tree with its reason, so the report still shows that the variant exists.

Quick start

Elara runs on Java 17 or later with JUnit 6. Add it as a test dependency: version 1.0.0 is published on Maven Central. Use the JUnit BOM to keep the Jupiter and Platform modules on 6.1.3, the version Elara is built and verified against.

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.junit</groupId>
            <artifactId>junit-bom</artifactId>
            <version>6.1.3</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.atp-fivt</groupId>
        <artifactId>elara</artifactId>
        <version>1.0.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Place your comparison class under src/test/java and run mvn test with Maven Surefire. Elara is discovered automatically on the test classpath.

The multiplication example runs two input rows against the GOOD and BUGGY variants returned by CalcSource (MulTest.java, CalcSource.java).

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.atpfivt.elara.api.ComparisonArguments;
import org.atpfivt.elara.api.ComparisonTest;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

@ComparisonTest(source = CalcSource.class)
class MulTest {
    @ParameterizedTest(quoteTextArguments = false)
    @ComparisonArguments(3)
    @CsvSource({ "2, 3, 6", "4, 5, 20" })
    void mul(int a, int b, int expected, Calc calc) {
        assertEquals(expected, calc.mul(a, b));
    }
}

Each input row has a separate result for each implementation. The example deliberately fails on the second row for Buggy, and the verification suite checks that failure.

mul(int, int, int, Calc)
├── [1] 2, 3, 6
│   ├── Good  
│   └── Buggy 
└── [2] 4, 5, 20
    ├── Good  
    └── Buggy  expected: <20> but was: (21)

Writing comparison tests

The comparison class

@ComparisonTest is a class annotation in org.atpfivt.elara.api. Its source names a ComparisonSource<V> implementation that selects the active enum variants. The test class must allow subclassing, so it must not be final, because Elara generates its Jupiter test class as a subclass.

The annotation has no Jupiter meta-annotations. Classes carrying it are run by the elara engine; the ordinary Jupiter engine ignores them.

Variants and the source

Variants are constants of an enum that implements Variant. The constant name identifies the variant in test selectors; testName() is the label shown in the test tree, and isOracle() marks a reference implementation.

public enum CalcVariant implements Variant {
    GOOD("Good", Calc.Good::new),
    BUGGY("Buggy", Calc.Buggy::new);
    ...
    @Override
    public String testName() {
        return testName;
    }
}

A ComparisonSource<V> has a no-argument constructor and three responsibilities:

variantType()

The enum class.

variants()

The active variants in discovery order. By default, all constants of the enum. Keep construction and this method free of resource startup: Elara calls them during discovery.

parameterResolvers(V variant)

The Jupiter ParameterResolver instances that supply the implementation parameters for one test invocation of that variant. Elara resolves the variant enum constant itself.

public final class CalcSource implements ComparisonSource<CalcSource.CalcVariant> {
    @Override
    public Class<CalcVariant> variantType() {
        return CalcVariant.class;
    }

    @Override
    public List<ParameterResolver> parameterResolvers(CalcVariant variant) {
        return List.of(new TypeBasedParameterResolver<Calc>() {
            @Override
            public Calc resolveParameter(ParameterContext parameter, ExtensionContext context) {
                return context.getStore(NAMESPACE).computeIfAbsent(Calc.class, key -> variant.create.get(), Calc.class);
            }
        });
    }
}

Method parameters

Elara supplies the current variant to a test parameter typed as the enum, as Variant, or as an interface of your own that extends Variant and that the enum implements. A variant’s parameter resolvers supply any parameters they support. Standard Jupiter resolvers, such as the one for TestInfo, are also available. See VariantTest.java.

@Test
void mulFourByFive(CalcVariant variant, Calc calc) {
    assertEquals(variant == BUGGY ? 21 : 20, calc.mul(4, 5));   // a known difference, pinned
}

@Test
void reportsTheVariant(Variant variant, TestInfo info) {
    assertEquals(variant.testName(), info.getDisplayName());
}

The same parameters are available to the test constructor under the default PER_METHOD lifecycle, and to @BeforeEach and @AfterEach methods.

For @ParameterizedTest, declare the argument-set parameters first, followed by the parameters supplied by Elara or other Jupiter resolvers. @ComparisonArguments(n) declares the number of leading argument-set parameters.

@ParameterizedTest
@ComparisonArguments(3)
@CsvSource({ "2, 3, 6", "4, 5, 20" })
void mul(int a, int b, int expected, Calc calc, TestInfo info) { /* ... */ }

The argument source runs once per method for each invocation of the enclosing test class. Every implementation in an input row receives the same source arguments. Local @MethodSource methods and @FieldSource fields must be static. Method-level parameter resolver extensions can supply parameters to a @MethodSource factory.

Repeated tests

A @RepeatedTest method runs every repetition on every implementation. Each repetition is a container with one leaf per implementation, like an argument set of a parameterized test, so the implementations can be compared repetition by repetition. The name pattern, a RepetitionInfo parameter, and the failureThreshold work as in Jupiter. The failure threshold is counted per implementation: an implementation that keeps failing is skipped once it reaches the threshold, while the others go on. See RepeatTest.java.

@RepeatedTest(5)
void mulFourByRepetition(RepetitionInfo repetition, Calc calc) {
    int b = repetition.getCurrentRepetition();
    assertEquals(4 * b, calc.mul(4, b));      // Buggy is wrong on 4 * 5: the fifth repetition
}

@RepeatedTest(value = 3, failureThreshold = 1, name = "attempt {currentRepetition}")
void mulFourByFive(Calc calc) {
    assertEquals(20, calc.mul(4, 5));         // Buggy fails attempt 1; its attempts 2 and 3 are skipped
}
mulFourByFive(Calc) 
├─ attempt 1 
│  ├─ Good 
│  └─ Buggy  expected: <20> but was: (21)
├─ attempt 2 
│  ├─ Good 
│  └─ Buggy  Failure threshold [1] exceeded
└─ attempt 3 
   ├─ Good 
   └─ Buggy  Failure threshold [1] exceeded

Skipping variants

To skip a variant on one method, use the library’s @Skip with the constant’s name, or declare a type-safe annotation for your enum once and mark it with @SkipMarker. Elara reads the annotation’s value() and, by convention, an optional description(). See Skip.java and SkipTest.java.

@Test
@Skip("ORACLE")                                            // org.atpfivt.elara.api.Skip, by name
@Skip(value = "MYSQL", description = "this type is buggy in MySQL")
void jsonColumn(Database db) { ... }

A project’s own annotation, typed with its enum:

@SkipMarker
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(Skip.List.class)
public @interface Skip {
    Database[] value();
    String description() default "";

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @interface List { Skip[] value(); }
}
@Test
@Skip(value = ORACLE, description = "this type is not supported on Oracle")
@Skip(value = MYSQL, description = "this type is buggy in MySQL")
void jsonColumn(Database db) { ... }

The contract Elara reads reflectively:

  • value() may return one constant or an array, typed with the source’s enum or named as strings. An unknown name or a constant of another enum invalidates the method, and the tree shows the reason.

  • description() is reported as the skip reason. Without one the reason names the annotation, for example skipped by @Skip.

  • The generated leaf is @Disabled with that reason, so runners report it as skipped and the source never creates the variant’s parameters. A method that is itself @Disabled ignores its skips.

  • Java only repeats an annotation through a container, so the nested List is needed for one description per variant, and a repeatable annotation and its enum must be public, because the JDK creates the container’s proxy outside their package. An array value() with a shared description needs no container.

Lifecycle

Elara calls the source’s no-argument constructor and reads variants() during discovery. Execution creates a fresh source instance and routes parameter requests to the variant’s resolvers.

A source is a Jupiter Extension and can implement callbacks:

  • BeforeAllCallback and AfterAllCallback for the comparison class;

  • the class-template invocation callbacks for each invocation of a parameterized class, and for each repetition of a repeated test;

  • BeforeEachCallback and AfterEachCallback for individual tests.

Use the Jupiter store to own closeable resources: register shared AutoCloseable resources in the store for Jupiter to close. ComparisonContext.classContext(context) locates the owning class or class-template invocation from a test or its resolver, and ComparisonContext.variant(context) returns the active variant of a test invocation.

Under the default PER_METHOD lifecycle, the test constructor can receive the variant and its arguments. @BeforeEach, the test, and @AfterEach also have access to them. Under PER_CLASS, the constructor runs at class scope. Variant-specific parameters are available in leaf methods and per-test callbacks.

See the source lifecycle verification for an example of per-leaf arguments backed by a shared resource, and LifecycleTest.java for the callback order.

Jupiter annotations and extensions

@Test, @ParameterizedTest, @RepeatedTest, @ParameterizedClass, and @TestInstance are supported. Execution annotations such as @Disabled, @Tag, @Timeout, and @ExtendWith apply to the generated implementation tests. Composed test annotations and instance-based @EnabledIf and @DisabledIf methods are covered by the compatibility tests.

A comparison class reports a skip with a reason for @Nested classes, @TestFactory methods, and custom @TestTemplate methods.

TestInfo.getDisplayName() returns Variant.testName(). Jupiter metadata exposed through TestInfo and ExtensionContext can identify generated classes and methods. Runners receive the original method as the test source for navigation.

Selection and reruns

The test tree follows class → method → argument set → variant. An ordinary @Test places the variants directly under the method. A @RepeatedTest has its repetitions where a parameterized test has its argument sets. A @ParameterizedClass adds its class invocation above the method.

The Launcher can select classes, methods, and individual nodes by UniqueId. A selection that combines all invocations of a parameterized class with individual invocations can execute additional leaves internally. Elara reports the selected nodes to the outer runner. With a parameterized class, method tags become visible when Jupiter materializes its invocations, so a discovery-time inclusion filter can depend on tags on the class itself.

How it works

  1. Runner. The IDE, Surefire, or the Launcher selects tests.

  2. Discovery. Elara finds @ComparisonTest classes and builds the test tree: class, method, argument set, variant.

  3. Generation. For each class it generates a subclass with one nested Jupiter class per method and one test per variant.

  4. Jupiter. The real Jupiter engine runs the selected variants, with its own parameter sources, lifecycle callbacks, and extensions.

  5. Reporting. Elara maps the results back onto the original test methods.

Jupiter handles parameter sources, lifecycle callbacks, and extensions on the generated tests. Elara reports results against the original test methods so runners can navigate to the test and select individual implementations. Extensions that inspect test metadata can see the generated classes and methods.

Runtime compatibility

Elara is compiled for Java 17, the minimum JUnit 6 supports, and runs on any later JDK. Building it needs JDK 21, and the build enforces that the library and its non-test dependencies stay within Java 17 bytecode. The verification suite uses JUnit Jupiter and Platform 6.1.3. Elara uses Jupiter’s generated-test metadata and identifier format for reruns, so use the verified version when integrating it. Elara generates test classes in the package of the user test, and a named Java module must open that package for the runtime lookup.

Project layout and contributing

The engine module contains the API and the JUnit Platform engine; its Javadoc is the API reference. The examples module demonstrates behavior, verification checks test trees, lifecycle, extension compatibility, and reruns through the Launcher API, and doc builds this guide and publishes the Javadoc next to it.

Building Elara needs JDK 21 and Maven 3.9 or later: the test sources use newer language features, and the build checks that the library and its dependencies stay compatible with Java 17. Run mvn clean verify before submitting a change; the root pom.xml also opens as a project in IntelliJ IDEA, where the examples run from the gutter. The build runs Checkstyle (checkstyle.xml) on all sources and SpotBugs (spotbugs-exclude.xml) on all classes, and every Java file must start with the Apache license header from checkstyle-header.txt. Every package needs a package-info.java, and every public or protected type and member needs a Javadoc comment with its @param and @return tags: Checkstyle checks the comments, and the Javadoc build fails on any doclint warning. The documentation sources (.adoc, .md) are spellchecked with aspell: run spellcheck and add project-specific words to allowed_spelling_words. For a bug report, include the JDK and JUnit versions, the runner, and a minimal test that reproduces the behavior: GitHub Issues.

License

Elara is released under the Apache License, Version 2.0.