Recall & Review
beginner
What does 'Multiple parameter types' mean in JUnit testing?
It means writing tests that accept different kinds of input values, like numbers and strings, to check how the code behaves with each type.
Click to reveal answer
intermediate
How do you supply multiple parameter types in a JUnit 5 parameterized test?
You use the @MethodSource annotation to provide a method that returns a Stream of Arguments, each containing different types of parameters.
Click to reveal answer
beginner
Why is testing with multiple parameter types useful?
It helps find bugs by checking if the code works correctly with different kinds of inputs, just like testing a recipe with different ingredients to see if it still tastes good.
Click to reveal answer
intermediate
Show a simple example of a JUnit 5 test method that accepts an int and a String as parameters.
@ParameterizedTest
@MethodSource("provideParameters")
void testWithMultipleTypes(int number, String text) {
assertNotNull(text);
assertTrue(number > 0);
}
static Stream<Arguments> provideParameters() {
return Stream.of(
Arguments.of(1, "one"),
Arguments.of(2, "two")
);
}
Click to reveal answer
intermediate
What is the role of the Arguments class in JUnit 5 parameterized tests?Arguments is used to bundle multiple parameters of different types together so they can be passed as one set of inputs to a test method.
Click to reveal answer
Which JUnit 5 annotation allows you to run a test with multiple sets of parameters?
✗ Incorrect
@ParameterizedTest runs the same test multiple times with different parameters.
How do you provide multiple parameter types to a JUnit 5 parameterized test?
✗ Incorrect
@MethodSource can return a Stream of Arguments, each with multiple parameter types.
What does the Arguments.of() method do in JUnit 5?
✗ Incorrect
Arguments.of() groups multiple parameters to pass them together to a test method.
Why is it important to test with multiple parameter types?
✗ Incorrect
Testing with different inputs helps find bugs and ensures code works in many situations.
Which of these is NOT a valid way to supply parameters in JUnit 5?
✗ Incorrect
@TestSource does not exist in JUnit 5.
Explain how to write a JUnit 5 parameterized test that accepts multiple parameter types.
Think about how to bundle different inputs and feed them to the test.
You got /4 concepts.
Why should you test your code with multiple parameter types? Give an example.
Imagine testing a calculator with positive and negative numbers.
You got /3 concepts.