JUnit Jupiter aggregator module providing a unified API for JUnit 5 testing framework with core API, parameterized tests, and test engine.
npx @tessl/cli install tessl/maven-org-junit-jupiter--junit-jupiter@5.12.0JUnit Jupiter is the new programming and extension model for JUnit 5, providing a comprehensive testing framework for Java applications. As an aggregator module, it combines the core JUnit Jupiter API, parameterized test support, and the Jupiter test engine to deliver a unified, modern testing experience with advanced features like nested tests, dynamic tests, custom extensions, and parallel execution.
pom.xml:<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.12.2</version>
<scope>test</scope>
</dependency>Or Gradle build.gradle:
testImplementation 'org.junit.jupiter:junit-jupiter:5.12.2'import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.*;Common static imports for assertions:
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.*;import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
class CalculatorTest {
@Test
@DisplayName("Addition should work correctly")
void testAddition() {
Calculator calc = new Calculator();
assertEquals(5, calc.add(2, 3));
assertNotNull(calc);
}
@BeforeEach
void setUp() {
// Setup before each test
System.out.println("Setting up test");
}
@AfterEach
void tearDown() {
// Cleanup after each test
System.out.println("Cleaning up test");
}
@ParameterizedTest
@ValueSource(ints = {1, 2, 3, 4, 5})
void testMultipleValues(int value) {
assertTrue(value > 0);
}
}JUnit Jupiter is built around several key components:
@Test, @BeforeEach, etc.)Essential testing annotations, lifecycle methods, and basic test structure. Provides the foundation for writing JUnit 5 tests with modern Java features.
@Test
@BeforeAll
@BeforeEach
@AfterEach
@AfterAll
@DisplayName(String value)
@Nested
@Disabled(String reason)
@Timeout(long value, TimeUnit unit)Comprehensive assertion methods for verifying test conditions and conditional test execution based on assumptions.
// Core assertions
static void assertEquals(Object expected, Object actual);
static void assertTrue(boolean condition);
static void assertThrows(Class<T> expectedType, Executable executable);
static void assertAll(Executable... executables);
// Assumptions
static void assumeTrue(boolean assumption);
static void assumingThat(boolean assumption, Executable executable);Advanced parameterized testing with multiple data sources, argument conversion, and aggregation for data-driven test scenarios.
@ParameterizedTest
@ValueSource(ints = {1, 2, 3})
@CsvSource({"1,John", "2,Jane"})
@MethodSource("argumentProvider")
void parameterizedTest(int value, String name);Powerful extension model for customizing test behavior, dependency injection, and integrating with external frameworks.
@ExtendWith(MyExtension.class)
@RegisterExtension
static MyExtension extension = new MyExtension();
interface Extension { }
interface BeforeAllCallback extends Extension;
interface ParameterResolver extends Extension;Rich set of conditions for controlling test execution based on operating system, JRE version, system properties, and custom conditions.
@EnabledOnOs(OS.LINUX)
@DisabledOnJre(JRE.JAVA_8)
@EnabledIfSystemProperty(named = "env", matches = "prod")
@EnabledIf("customCondition")Runtime test generation and nested test organization for complex test scenarios and hierarchical test structure.
@TestFactory
Stream<DynamicTest> dynamicTests();
static DynamicTest dynamicTest(String displayName, Executable executable);
static DynamicContainer dynamicContainer(String displayName, Stream<DynamicNode> children);Configuration for parallel test execution, resource locking, and temporary file management for performance optimization.
@Execution(ExecutionMode.CONCURRENT)
@ResourceLock("database")
@TempDir
Path tempDirectory;interface TestInfo {
String getDisplayName();
Set<String> getTags();
Optional<Class<?>> getTestClass();
Optional<Method> getTestMethod();
}
interface TestReporter {
void publishEntry(Map<String, String> map);
void publishEntry(String key, String value);
}
interface RepetitionInfo {
int getCurrentRepetition();
int getTotalRepetitions();
}class AssertionFailureBuilder {
static AssertionFailureBuilder assertionFailure();
AssertionFailureBuilder message(String message);
AssertionFailureBuilder expected(Object expected);
AssertionFailureBuilder actual(Object actual);
AssertionFailedError build();
}@FunctionalInterface
interface Executable {
void execute() throws Throwable;
}
@FunctionalInterface
interface ThrowingSupplier<T> {
T get() throws Throwable;
}
@FunctionalInterface
interface ThrowingConsumer<T> {
void accept(T t) throws Throwable;
}