0
0
JUnittesting~5 mins

@ParameterizedTest annotation in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @ParameterizedTest annotation in JUnit?
It allows running the same test method multiple times with different inputs, making tests more efficient and reducing code duplication.
Click to reveal answer
beginner
How do you supply different input values to a @ParameterizedTest?
You use source annotations like @ValueSource, @CsvSource, or @MethodSource to provide the test data.
Click to reveal answer
intermediate
What happens if a @ParameterizedTest fails for one input value?
Only the test run for that specific input fails; other inputs are tested independently, so you get detailed feedback on which inputs passed or failed.
Click to reveal answer
beginner
Can @ParameterizedTest methods have parameters? If yes, how are they used?
Yes, the method parameters receive the input values from the source annotations for each test run.
Click to reveal answer
beginner
Name two source annotations commonly used with @ParameterizedTest.
@ValueSource for simple values like ints or strings, and @CsvSource for multiple comma-separated values.
Click to reveal answer
What does the @ParameterizedTest annotation do in JUnit?
ARuns a test multiple times with different inputs
BMarks a test to be ignored
CRuns a test only once
DGroups multiple tests together
Which annotation is used to provide a list of simple values to a @ParameterizedTest?
A@CsvSource
B@Test
C@ValueSource
D@BeforeEach
How do you provide multiple parameters per test run in a @ParameterizedTest?
AUsing <code>@CsvSource</code>
BUsing <code>@ValueSource</code>
CUsing <code>@Test</code>
DUsing <code>@BeforeAll</code>
If a @ParameterizedTest method has parameters, where do these values come from?
AFrom the test method itself
BFrom the source annotations like <code>@ValueSource</code>
CFrom the class constructor
DFrom the test report
What is the result if one input value causes a @ParameterizedTest to fail?
AThe test passes anyway
BAll test runs fail
CThe test is skipped
DOnly the run with that input fails
Explain how @ParameterizedTest helps improve test code and give an example of a source annotation you can use.
Think about running one test method with many inputs.
You got /3 concepts.
    Describe how you write a @ParameterizedTest method that tests if numbers are even using @ValueSource.
    Imagine testing multiple numbers in one test method.
    You got /3 concepts.