JUNIT / CATATAN</>↗JUnit12 Jul 2026
To run only selected JUnit 5 tests by tag, mark your tests with @Tag, then configure your build tool or IDE to include only that tag. 1. Add tags to your tests import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; class PaymentServiceTest { @Test @Tag("fast") void calculatesTotal() { // test code } @Test @Tag("integration") void connectsToPaymentGateway() { // test […]
JUNIT / CATATAN</>↗JUnit12 Jul 2026
In JUnit 5, you can use the @Tag annotation to group tests into categories such as: fast slow unit integration database api smoke Tags are useful when you want to run only certain groups of tests, for example only fast unit tests during development, or only integration tests in a CI pipeline. 1. Basic Example […]
JUNIT / CATATAN</>↗JUnit11 Jul 2026
@EnumSource is a JUnit 5 parameterized-test source that runs the same test once for each selected enum constant. Basic usage import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; import static org.junit.jupiter.api.Assertions.assertNotNull; class DirectionTest { enum Direction { NORTH, SOUTH, EAST, WEST } @ParameterizedTest @EnumSource(Direction.class) void shouldTestAllDirections(Direction direction) { assertNotNull(direction...
JUNIT / CATATAN</>↗JUnit11 Jul 2026
In JUnit 5, @MethodSource lets you supply test arguments from one or more factory methods. It is commonly used with @ParameterizedTest when your test data is too complex for @ValueSource or @CsvSource. Basic example import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertTrue; class StringTest { @ParameterizedTest @MethodSource("blankStrings")...
JUNIT / CATATAN</>↗JUnit11 Jul 2026
Use JUnit 5’s @CsvFileSource with a parameterized test to load rows from a CSV file and pass each row into your test method. 1. Add the CSV file Place the CSV file under src/test/resources, for example: src/test/resources/test-data/users.csv Example CSV: username,age,active alice,30,true bob,25,false charlie,40,true 2. Use @CsvFileSource import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvFileSource; import static org.junit.jupiter.a...
JUNIT / CATATAN</>↗JUnit11 Jul 2026
To use @CsvSource in JUnit 5 parameterized tests, you define multiple sets of comma-separated input values directly inside the annotation. Each CSV row becomes one test invocation. 1. Add the Required Imports import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import static org.junit.jupiter.api.Assertions.assertEquals; @CsvSource is part of JUnit Jupiter Params, so make sure your project includes the parameterized test […]