B. The annotation @ParameterizedTest does not support 'name' attribute
C. The placeholder {0} cannot be used for int parameters
D. The method parameter type int is invalid for @ValueSource
Solution
Step 1: Check if 'name' attribute is valid in @ParameterizedTest
@ParameterizedTest supports the 'name' attribute to customize display names.
Step 2: Verify placeholders and parameter types
{0} correctly refers to the first parameter, which can be an int from @ValueSource.
Step 3: Confirm method and annotation compatibility
Using int parameter with @ValueSource(ints = {...}) is valid and assertTrue is a valid assertion.
Final Answer:
There is no error; the code is correct -> Option A
Quick Check:
Valid syntax and usage = no error [OK]
Hint: Check if syntax matches JUnit 5 docs exactly [OK]
Common Mistakes:
Thinking {0} can't be used with primitive types
Believing 'name' attribute is unsupported
Confusing parameter types with annotation requirements
5. You want to create a parameterized test in JUnit 5 that shows the test index, parameter value, and a custom message "Check value" in the display name. Which of the following is the correct way to write the @ParameterizedTest annotation to achieve this?
hard
A. @ParameterizedTest(name = "{index} - {0} - Check value")
B. @ParameterizedTest(name = "Test {index}: {0} - Check value")
C. @ParameterizedTest(name = "Check value - {index} - {0}")
D. All of the following are correct
Solution
Step 1: Understand the 'name' attribute flexibility
The 'name' attribute accepts any string with placeholders {index} and {0} to customize display names.
Step 2: Check each option's format
The three provided formats all correctly use {index} and {0} with additional text to form valid display names.
Step 3: Confirm all options are valid
Since all formats are syntactically correct and achieve the goal, all are acceptable.
Final Answer:
All of the following are correct -> Option D
Quick Check:
Any string with {index} and {0} works [OK]
Hint: Any string with {index} and {0} placeholders is valid [OK]
Common Mistakes:
Thinking only one exact format is allowed
Misplacing placeholders causing syntax errors
Forgetting to include both {index} and {0}
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.