Recall & Review
beginner
What does the @NullAndEmptySource annotation do in JUnit?
It provides both null and empty values as arguments to a parameterized test method, allowing you to test how your code handles these special cases.
Click to reveal answer
intermediate
How is @NullAndEmptySource different from @NullSource and @EmptySource?
@NullAndEmptySource combines the effects of @NullSource (which provides null) and @EmptySource (which provides empty values like empty strings or collections) in one annotation.
Click to reveal answer
beginner
Show a simple example of a JUnit test method using @NullAndEmptySource.
@ParameterizedTest
@NullAndEmptySource
void testWithNullAndEmpty(String input) {
assertTrue(input == null || input.isEmpty());
}
Click to reveal answer
beginner
Why is it useful to test with null and empty inputs?
Because null and empty inputs are common edge cases that can cause bugs if not handled properly. Testing them helps ensure your code is robust and error-free.
Click to reveal answer
intermediate
Can @NullAndEmptySource be used with any parameter type?
No, it works with parameters that can accept null and empty values, such as String, Collections, or arrays. It won't work properly with primitive types like int or boolean.
Click to reveal answer
What values does @NullAndEmptySource provide to a parameterized test?
✗ Incorrect
@NullAndEmptySource provides both null and empty values to test how the method handles these cases.
Which annotation combines the effects of @NullSource and @EmptySource?
✗ Incorrect
@NullAndEmptySource is a shortcut that includes both null and empty values.
Can @NullAndEmptySource be used with primitive parameter types like int?
✗ Incorrect
@NullAndEmptySource works with reference types that can be null or empty, not primitives.
Why should you test with null and empty inputs?
✗ Incorrect
Null and empty inputs are common edge cases that can cause bugs if not handled.
Which of these is NOT provided by @NullAndEmptySource?
✗ Incorrect
@NullAndEmptySource only provides null and empty values, not random integers.
Explain how @NullAndEmptySource helps improve test coverage in parameterized tests.
Think about why null and empty inputs are important to test.
You got /4 concepts.
Describe a scenario where using @NullAndEmptySource would be beneficial in your tests.
Consider common input problems in real applications.
You got /4 concepts.