O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

@ArgumentsSource

The last annotation aimed to specify the source of arguments for parameterized tests in JUnit 5 is @ArgumentsSource. With this annotation, we can specify a custom (and reusable in different tests) class, which will contain the parameters for the test. This class must implement the interface org.junit.jupiter.params.provider.ArgumentsProvider.

Let’s see an example. The following class implements a Jupiter parameterized test, in which the arguments source will be defined in the class CustomArgumentsProvider1:

package io.github.bonigarcia;import static org.junit.jupiter.api.Assertions.assertNotNull;import static org.junit.jupiter.api.Assertions.assertTrue;import org.junit.jupiter.params.ParameterizedTest;import org.junit.jupiter.params.provider.ArgumentsSource; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required