Is JUnit Engine required for your test suite to run?

Viewed 26

Does a test suite requires junit-jupiter-engine as a dependency, or junit-jupiter-api is enough?

Under a post in Stack Overflow - Difference between junit-jupiter-api and junit-jupiter-engine, I have found that both dependencies are essential for our test suite to run. However, excersising the following simple test suite works without having the former dependency.

@Test
void testNull() {
    assertThatThrownBy(() -> {
        strategy.sort(null);
    }).isInstanceOf(NullPointerException.class);
}

@Test
void testEmptyArray() {
    int[] arr = new int[0];
    strategy.sort(arr);

    assertThat(arr).isEmpty();
}

@Test
void testUniqueEntries() {
    int[] arr = {1, 2, 14, 3, 45, 7, 24, 13};
    int[] expected = {1, 2, 3, 7, 13, 14, 24, 45};
    strategy.sort(arr);

    assertThat(arr).isEqualTo(expected);
}

@Test
void testDuplicationEntries() {
    int[] arr = {1, 5, 3, 7, 4, 3, 8, 2};
    int[] expected = {1, 2, 3, 3, 4, 5, 7, 8};
    strategy.sort(arr);

    assertThat(arr).isEqualTo(expected);
}

I think I'm yet incapable of telling the concrete difference between the engine and the API, so I would appreciate any comment on the topic. (A real-world analogy would be of a great help.)

1 Answers

Yes, you need the junit-jupiter-engine dependancy to trigger the tests during your builds.

The API is just the tooling that helps you writing junit tests, the engine runs the tests.

Related