0

I would like to define a custom descriptor for the display name of a testcase in a Junit5 ParameterizedTest. Here is my current solution:

/**
 * @param name
 *            is the testcase display name
 */
@ParameterizedTest(name = "{0}")
@MethodSource
void testNotNull(final String name, final String value) {
    assertNotNull(sut.bar(value));
}

private static Stream<Arguments> testNotNull() {
    return Stream.of(Arguments.of("empty string", ""),
                     Arguments.of("string with no alphanumerical prefix", "123"),
                     Arguments.of("null string", null));
}

The only thing I dislike about this solution is having to define a JavaDoc Parameter for name in order to avoid warnings in my IDE.

Is there a better way to achieve this?

  • Does this answer your question? [Generating display names for @ParameterizedTest in JUnit 5](https://stackoverflow.com/questions/57892989/generating-display-names-for-parameterizedtest-in-junit-5) – beatngu13 Sep 13 '21 at 13:09
  • That is the same as my example above. – user13774030 Sep 14 '21 at 06:04
  • Have you had a look at the [accepted answer](https://stackoverflow.com/a/66994980/3429133)? It is different from your current solution as it uses the new `Named` interface. – beatngu13 Sep 14 '21 at 12:39
  • Thank you, I was looking at the top answer. Yes that seems perfect, I just need to update Junit. Thanks again! – user13774030 Sep 17 '21 at 07:59

0 Answers0