0
0
JUnittesting~5 mins

Custom display names for parameters in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of custom display names for parameters in JUnit tests?
Custom display names make test output easier to read by showing meaningful names for parameters instead of default values or indexes.
Click to reveal answer
beginner
How do you specify a custom display name for a parameter in a JUnit 5 parameterized test?
Use the @ParameterizedTest annotation with the name attribute, for example: @ParameterizedTest(name = "Test with input={0} and expected={1}").
Click to reveal answer
intermediate
What placeholders can you use in the name attribute for custom display names in JUnit 5 parameterized tests?
You can use placeholders like {index} for the invocation index, {0}, {1}, etc. for parameter values by position.
Click to reveal answer
beginner
Why is using custom display names for parameters helpful when running tests in an IDE or CI environment?
It helps quickly identify which input caused a test failure without digging into the code or logs, improving debugging speed.
Click to reveal answer
beginner
Show a simple example of a JUnit 5 parameterized test method with a custom display name for parameters.
@ParameterizedTest(name = "Run {index}: input={0}, expected={1}") @CsvSource({"apple, 5", "banana, 6"}) void testLength(String input, int expected) { assertEquals(expected, input.length()); }
Click to reveal answer
What annotation attribute in JUnit 5 allows you to set custom display names for parameterized test runs?
Avalue
Bname
CdisplayName
Dlabel
Which placeholder represents the current test invocation index in a JUnit 5 parameterized test name?
A{run}
B{param}
C{count}
D{index}
In the name attribute, how do you refer to the first parameter's value?
A{param1}
B{1}
C{0}
D{first}
Why should you use custom display names for parameters in tests?
ATo improve test output readability
BTo make test code shorter
CTo speed up test execution
DTo avoid writing assertions
Which JUnit 5 annotation is used to run a test multiple times with different parameters?
A@ParameterizedTest
B@TestFactory
C@RepeatedTest
D@Test
Explain how to create custom display names for parameters in a JUnit 5 parameterized test and why it is useful.
Think about how test output looks and how placeholders work.
You got /4 concepts.
    Describe the placeholders available for custom display names in JUnit 5 parameterized tests and give an example of their usage.
    Focus on how to refer to parameters and the test run number.
    You got /3 concepts.