Complete the code to provide integer values to the test method using @ValueSource.
@ParameterizedTest @ValueSource([1]) void testWithInts(int number) { assertTrue(number > 0); }
The correct syntax to provide integer values is @ValueSource(ints = {1, 2, 3, 4}). This passes the integers 1, 2, 3, and 4 to the test method.
Complete the code to provide string values to the test method using @ValueSource.
@ParameterizedTest
@ValueSource([1])
void testWithStrings(String word) {
assertNotNull(word);
}To pass string values, use @ValueSource(strings = {"apple", "banana", "cherry"}). This sends the strings to the test method.
Fix the error in the @ValueSource annotation to correctly provide double values.
@ParameterizedTest @ValueSource([1]) void testWithDoubles(double value) { assertTrue(value > 0.0); }
The correct attribute for double values is 'doubles'. So use @ValueSource(doubles = {1.0, 2.5, 3.3}).
Fill both blanks to create a test that uses @ValueSource to pass characters and asserts they are letters.
@ParameterizedTest @ValueSource([1]) void testWithChars(char letter) { assertTrue(Character.[2](letter)); }
Use @ValueSource(chars = {'a', 'b', 'c'}) to pass characters. The assertion uses Character.isLetter(letter) to check if the character is a letter.
Fill all three blanks to create a test using @ValueSource with strings and assert their length is greater than zero.
@ParameterizedTest @ValueSource([1]) void testStringLength([2] word) { assertTrue(word.[3]() > 0); }
Use @ValueSource(strings = {"test", "java", "junit"}) to pass strings. The method parameter type is String. The assertion calls word.length() to check the string length.