I have many boolean methods like boolean isPalindrome(String txt)
to test.
At the moment I test each of these methods with two parameterised tests, one for true
results and one for false
results:
@ParameterizedTest
@ValueSource(strings = { "racecar", "radar", "able was I ere I saw elba" })
void test_isPalindrome_true(String candidate) {
assertTrue(StringUtils.isPalindrome(candidate));
}
@ParameterizedTest
@ValueSource(strings = { "peter", "paul", "mary is here" })
void test_isPalindrome_false(String candidate) {
assertFalse(StringUtils.isPalindrome(candidate));
}
Instead I would like to test these in one parameterised method, like this pseudo Java code:
@ParameterizedTest
@ValueSource({ (true, "racecar"),(true, "radar"), (false, "peter")})
void test_isPalindrome(boolean res, String candidate) {
assertEqual(res, StringUtils.isPalindrome(candidate));
}
Is there a ValueSource for this? Or is there an other way to achieve this in a concise manner?