Skip to content

Instantly share code, notes, and snippets.

@eliasnogueira
Last active March 23, 2023 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliasnogueira/8319537645519a8fe3fad0519be32dbd to your computer and use it in GitHub Desktop.
Save eliasnogueira/8319537645519a8fe3fad0519be32dbd to your computer and use it in GitHub Desktop.
JUnit 5 - When to use @valuesource: test example
class AgeTest {
@DisplayName("Valid ages")
@ParameterizedTest(name = "{0} is a valid age for the requirement 18 to 30")
@ValueSource(ints = {18, 19, 29, 30})
void validAges(int age) {
Assertions.assertThat(isAgeValid(age)).isTrue();
}
@DisplayName("Invalid ages")
@ParameterizedTest(name = "{0} is an invalid age for the requirement between 18 to 30")
@ValueSource(ints = {17, 31})
void invalidAges(int age) {
Assertions.assertThat(isAgeValid(age)).isFalse();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment