1

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.)

Kaloyan
  • 41
  • 1
  • 6

1 Answers1

0

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.

DamCx
  • 1,047
  • 1
  • 11
  • 25
  • Perhaps it's a misunderstanding on my side, but how do the tests build and run while the dependency of the engine is not present if it is required? – Kaloyan Jul 14 '22 at 08:14
  • The tests won't run if the engine isn't present. But you still can write them while using the API – DamCx Jul 25 '22 at 13:12