Testing tooling

JUnit @ValueSource

Provides one argument per invocation. Framework or debugger behavior source-reviewed; actual tool execution NOT RUN.

Formal Syntax & Structure

java syntaxjava
@ValueSource(ints = {-1,-2})

Working Example

Example Snippetjava
package example.books;
import org.junit.jupiter.params.ParameterizedTest;import org.junit.jupiter.params.provider.CsvSource;import org.junit.jupiter.params.provider.ValueSource;import org.junit.jupiter.api.Test;import static org.junit.jupiter.api.Assertions.*;
class BoundaryTest {    @ParameterizedTest    @CsvSource({"0,250,0", "1,250,250", "3,250,750",                "2,17,34", "5,0,0", "2147483647,1,2147483647"})    void totals(int count, int price, int expected) {        assertEquals(expected, Receipt.totalCents(count, price));    }
    @ParameterizedTest    @ValueSource(ints = {-1, -2, Integer.MIN_VALUE})    void negativePrice(int price) {        assertThrows(IllegalArgumentException.class,                () -> Receipt.totalCents(2, price));    }
    @Test    void detectsOverflow() {        assertThrows(ArithmeticException.class,                () -> Receipt.totalCents(Integer.MAX_VALUE, 2));    }}
Java Reference