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?✗ Incorrect
@ParameterizedTest runs the same test method multiple times with different input values.
Which annotation is used to provide a list of simple values to a
@ParameterizedTest?✗ Incorrect
@ValueSource supplies simple values like ints or strings to parameterized tests.
How do you provide multiple parameters per test run in a
@ParameterizedTest?✗ Incorrect
@CsvSource allows multiple comma-separated values per test run.
If a
@ParameterizedTest method has parameters, where do these values come from?✗ Incorrect
The parameters are injected from the source annotations that provide test data.
What is the result if one input value causes a
@ParameterizedTest to fail?✗ Incorrect
Only the test run with the failing input fails; others run independently.
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.