Recall & Review
beginner
What is a Custom Argument Provider in JUnit?
A Custom Argument Provider is a way to supply test method parameters dynamically by implementing the
ArgumentsProvider interface. It allows you to control the test data for parameterized tests beyond simple static values.Click to reveal answer
beginner
Which interface must you implement to create a Custom Argument Provider in JUnit?
You must implement the
org.junit.jupiter.params.provider.ArgumentsProvider interface and override the provideArguments(ExtensionContext context) method.Click to reveal answer
intermediate
How do you link a Custom Argument Provider to a parameterized test method?
You create a custom annotation annotated with
@ArgumentsSource(YourCustomProvider.class) and then use that annotation on the test method.Click to reveal answer
intermediate
What type of object does the
provideArguments method return?It returns a
Stream<Arguments>, where each Arguments instance represents a set of parameters for one test invocation.Click to reveal answer
advanced
Why use a Custom Argument Provider instead of @ValueSource or @CsvSource?
Custom Argument Providers allow complex, dynamic, or external data sources for test parameters, such as reading from files, databases, or generating data programmatically, which static sources cannot handle.
Click to reveal answer
Which method must be overridden when creating a Custom Argument Provider in JUnit?
✗ Incorrect
The
ArgumentsProvider interface requires overriding provideArguments(ExtensionContext context) to supply test arguments.What does the
Arguments class represent in JUnit parameterized tests?✗ Incorrect
Arguments holds the parameters passed to a single invocation of a parameterized test.How do you connect a Custom Argument Provider to a test method parameter?
✗ Incorrect
You use
@ArgumentsSource(YourProvider.class) to link the custom provider to the test parameter.Which Java type does the
provideArguments method return?✗ Incorrect
The method returns a
Stream<Arguments> to supply multiple argument sets.Why might you prefer a Custom Argument Provider over @CsvSource?
✗ Incorrect
Custom providers allow dynamic or external data sources, unlike static @CsvSource.
Explain how to create and use a Custom Argument Provider in JUnit parameterized tests.
Think about the interface, method, return type, and how to connect it to the test.
You got /5 concepts.
Describe scenarios where a Custom Argument Provider is more useful than built-in sources like @ValueSource or @CsvSource.
Consider limitations of static data sources.
You got /4 concepts.