0
0
JUnittesting~10 mins

@NullSource and @EmptySource in JUnit - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a null input test using @NullSource.

JUnit
@ParameterizedTest
@[1]
void testWithNullInput(String input) {
    assertNull(input);
}
Drag options to blanks, or click blank then click option'
ACsvSource
BEmptySource
CValueSource(strings = {""})
DNullSource
Attempts:
3 left
💡 Hint
Common Mistakes
Using @EmptySource instead of @NullSource for null input.
Forgetting to annotate the test with @ParameterizedTest.
2fill in blank
medium

Complete the code to add an empty input test using @EmptySource.

JUnit
@ParameterizedTest
@[1]
void testWithEmptyInput(String input) {
    assertEquals("", input);
}
Drag options to blanks, or click blank then click option'
AEmptySource
BNullSource
CValueSource(strings = {"null"})
DCsvSource
Attempts:
3 left
💡 Hint
Common Mistakes
Using @NullSource instead of @EmptySource for empty string input.
Not using @ParameterizedTest annotation.
3fill in blank
hard

Fix the error in the code to test both null and empty inputs using @NullSource and @EmptySource.

JUnit
@ParameterizedTest
@NullSource
@[1]
void testWithNullAndEmpty(String input) {
    assertTrue(input == null || input.isEmpty());
}
Drag options to blanks, or click blank then click option'
ACsvSource
BEmptySource
CNullSource
DValueSource(strings = {""})
Attempts:
3 left
💡 Hint
Common Mistakes
Using @ValueSource(strings = {""}) instead of @EmptySource.
Using @NullSource twice.
4fill in blank
hard

Fill both blanks to create a parameterized test that checks null and empty inputs with proper annotations.

JUnit
@ParameterizedTest
@[1]
@[2]
void testNullAndEmptyInputs(String input) {
    assertTrue(input == null || input.isEmpty());
}
Drag options to blanks, or click blank then click option'
ANullSource
BEmptySource
CValueSource(strings = {""})
DCsvSource
Attempts:
3 left
💡 Hint
Common Mistakes
Using @ValueSource instead of @EmptySource.
Missing one of the annotations.
5fill in blank
hard

Fill all three blanks to create a parameterized test that uses @NullSource, @EmptySource, and a @ValueSource with strings.

JUnit
@ParameterizedTest
@[1]
@[2]
@[3](strings = {"test", "example"})
void testMultipleInputs(String input) {
    assertNotNull(input);
}
Drag options to blanks, or click blank then click option'
ANullSource
BEmptySource
CValueSource
DCsvSource
Attempts:
3 left
💡 Hint
Common Mistakes
Using @CsvSource instead of @ValueSource for simple string inputs.
Forgetting to add @ParameterizedTest annotation (not shown here).