Skip to content

Instantly share code, notes, and snippets.

@eliasnogueira
Created June 15, 2023 20:00
Show Gist options
  • Save eliasnogueira/c760551493c3aae589c3e4c906532d97 to your computer and use it in GitHub Desktop.
Save eliasnogueira/c760551493c3aae589c3e4c906532d97 to your computer and use it in GitHub Desktop.
Simple example that explain how the MethodSource annotation from JUnit 5 works
class MyTestClass {
@DisplayName("Date must be from the current year")
@ParameterizedTest(name = "Check the current year of {0}")
@MethodSource("dateList")
void myTest(LocalDate date) {
assertThat(date).hasYear(2023);
}
static Stream<Arguments> dateList() {
return Stream.of(
Arguments.arguments(LocalDate.parse("2023-08-15")),
Arguments.arguments(LocalDate.parse("2023-03-01")),
Arguments.arguments(LocalDate.parse("2023-10-23"))
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment