0Pricing
Java Academy · Lesson

Parameterized Tests with @CsvSource and @MethodSource

Run the same test with multiple input sets using @ParameterizedTest, @CsvSource, and @MethodSource.

Why Parameterized Tests?

Running the same test logic with multiple input sets reveals edge cases without copy-pasting test methods. JUnit 5 supports parameterized tests natively with @ParameterizedTest.

@ValueSource: Simple Single-Value Tests

@ValueSource provides a single parameter of a given type. The test runs once per value.

@ParameterizedTest
@ValueSource(strings = {"", "  ", "\t"})
void blank_strings_are_rejected(String input) {
    assertThrows(IllegalArgumentException.class, () -> validator.validate(input));
}

All lessons in this course

  1. Parameterized Tests with @CsvSource and @MethodSource
  2. Mockito Advanced: Argument Captors and Spies
  3. Spring Boot Test Slices: @WebMvcTest and @DataJpaTest
  4. Testcontainers: Real Database Integration Tests
← Back to Java Academy