Recall & Review
beginner
What is argument conversion in JUnit?
Argument conversion is the process where JUnit automatically changes the test method's input parameters from strings (like those in @ParameterizedTest) into the required data types before running the test.
Click to reveal answer
intermediate
How does JUnit know how to convert a String argument to a custom object?
JUnit looks for a constructor or a static method in the custom class that takes a single String argument to convert the input string into the object.Click to reveal answer
intermediate
Which annotation in JUnit 5 allows you to provide a custom argument converter?
You use the @ConvertWith annotation to specify a custom ArgumentConverter class that tells JUnit how to convert the input argument.Click to reveal answer
beginner
True or False: JUnit can only convert arguments to primitive types automatically.
False. JUnit can convert to many types automatically, including primitives, wrappers, enums, and even custom types if they have the right constructor or static method.
Click to reveal answer
beginner
What happens if JUnit cannot convert a parameter to the required type during a parameterized test?
The test will fail with an error indicating that the argument conversion failed, usually showing a message about no suitable constructor or method found.
Click to reveal answer
In JUnit, which of these is NOT a way JUnit converts a String argument to a parameter type?
✗ Incorrect
JUnit does not use the toString() method for argument conversion. It uses constructors, static methods like valueOf, or custom converters with @ConvertWith.
What annotation do you use to specify a custom argument converter in JUnit?
✗ Incorrect
The correct annotation to specify a custom argument converter is @ConvertWith.
If you have a parameterized test method with a parameter of type MyClass, how can JUnit convert a String to MyClass automatically?
✗ Incorrect
JUnit can convert if MyClass has either a constructor that takes a String or a static method named valueOf(String).
What will happen if JUnit fails to convert an argument in a parameterized test?
✗ Incorrect
JUnit will fail the test and report an error about argument conversion failure.
Which of these types can JUnit convert automatically without custom converters?
✗ Incorrect
JUnit can automatically convert primitive types, their wrapper classes, and enums.
Explain how JUnit converts String arguments to method parameters in parameterized tests.
Think about constructors, static methods, and annotations.
You got /3 concepts.
Describe what you would do if JUnit cannot convert a String argument to your custom class in a parameterized test.
Consider custom converters and annotations.
You got /3 concepts.