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

@ValueSource

The annotation @ValueSource is used in conjunction with @ParameterizedTest to specify a parameterized test in which the argument source is an array of literal values of String, int, long, or double. These values are specified inside the annotation, using the elements strings, ints, longs, or doubles. Consider the following example:

package io.github.bonigarcia;import static org.junit.jupiter.api.Assertions.assertNotNull;import org.junit.jupiter.params.ParameterizedTest;import org.junit.jupiter.params.provider.ValueSource;class ValueSourceStringsParameterizedTest {    @ParameterizedTest    @ValueSource(strings = { "Hello", "World" })    void testWithStrings(String argument) {      System.out.println("Parameterized test with (String) parameter: ...

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