Last active
March 23, 2023 19:53
-
-
Save eliasnogueira/8319537645519a8fe3fad0519be32dbd to your computer and use it in GitHub Desktop.
JUnit 5 - When to use @valuesource: test example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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