0
0
JUnittesting~20 mins

Multiple parameter types in JUnit - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JUnit Multiple Parameter Types Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of JUnit test with multiple parameter types
Consider the following JUnit 5 parameterized test method using @CsvSource with mixed parameter types. What will be the test execution result for the given inputs?
JUnit
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import static org.junit.jupiter.api.Assertions.*;

class CalculatorTest {
    @ParameterizedTest
    @CsvSource({
        "2, 3, 5",
        "-1, 1, 0",
        "0, 0, 0",
        "5, -3, 2"
    })
    void testAdd(int a, int b, int expected) {
        assertEquals(expected, a + b);
    }
}
AThe test with inputs (0, 0, 0) throws a runtime exception.
BThe test with inputs (5, -3, 2) fails due to wrong expected value.
CThe test with inputs (-1, 1, 0) fails due to type mismatch error.
DAll 4 tests pass successfully.
Attempts:
2 left
💡 Hint
Check the addition results for each input set carefully.
assertion
intermediate
1:30remaining
Correct assertion for mixed parameter types in JUnit
You have a parameterized test method with parameters: String name, int age, boolean active. Which assertion correctly verifies that age is greater than 18 and active is true?
JUnit
import static org.junit.jupiter.api.Assertions.*;

void testUser(String name, int age, boolean active) {
    // Which assertion is correct?
}
AassertFalse(age <= 18 || !active);
BassertEquals(true, age > 18 && active);
CassertTrue(age > 18 && active);
DassertTrue(age > 18 || active);
Attempts:
2 left
💡 Hint
Use assertTrue with the exact condition you want to verify.
🔧 Debug
advanced
2:30remaining
Identify the cause of failure in mixed parameter JUnit test
Given this parameterized test using @MethodSource, why does the test fail with a ParameterResolutionException?
JUnit
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.stream.Stream;

class UserTest {
    static Stream<Object[]> userProvider() {
        return Stream.of(
            new Object[]{"Alice", 30, true},
            new Object[]{"Bob", "twenty", false}
        );
    }

    @ParameterizedTest
    @MethodSource("userProvider")
    void testUser(String name, int age, boolean active) {
        // test logic
    }
}
AThe second parameter '"twenty"' cannot be converted to int, causing the failure.
BThe method userProvider() is not static, causing the failure.
CThe test method parameters do not match the provider method return type.
DThe boolean parameter 'active' is not boxed, causing the failure.
Attempts:
2 left
💡 Hint
Check the types of values provided for each parameter.
framework
advanced
1:30remaining
JUnit 5 parameterized test with multiple parameter types and custom converter
Which JUnit 5 feature allows you to convert a String parameter to a custom object type in a parameterized test?
A@ConvertWith annotation with a custom ArgumentConverter implementation
B@CsvSource with inline lambda conversion
C@ValueSource with a custom parser method
D@MethodSource with automatic type inference
Attempts:
2 left
💡 Hint
Look for annotations that handle parameter conversion explicitly.
🧠 Conceptual
expert
3:00remaining
Handling multiple parameter types in JUnit parameterized tests with null values
In a JUnit 5 parameterized test with parameters (String name, Integer age, Boolean active), which approach correctly allows passing null values for age and active using @CsvSource?
AUse empty strings for nulls and annotate the test method with @NullAndEmptySource
BUse the string 'null' in @CsvSource and annotate parameters with @ConvertWith(NullConverter.class)
CUse the string 'null' in @CsvSource and annotate the test method with @NullSource
DUse the string 'null' in @CsvSource and annotate parameters with @NullAndEmptySource
Attempts:
2 left
💡 Hint
Consider how JUnit converts string literals to null for non-String parameters.