or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

assertions.mdconditional-execution.mdcore-testing.mddynamic-tests.mdextensions.mdindex.mdparallel-execution.mdparameterized-tests.md

index.mddocs/

0

# JUnit Jupiter

1

2

JUnit 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.

3

4

## Package Information

5

6

- **Package Name**: org.junit.jupiter:junit-jupiter

7

- **Package Type**: Maven

8

- **Language**: Java

9

- **Installation**: Add to Maven `pom.xml`:

10

11

```xml

12

<dependency>

13

<groupId>org.junit.jupiter</groupId>

14

<artifactId>junit-jupiter</artifactId>

15

<version>5.12.2</version>

16

<scope>test</scope>

17

</dependency>

18

```

19

20

Or Gradle `build.gradle`:

21

22

```groovy

23

testImplementation 'org.junit.jupiter:junit-jupiter:5.12.2'

24

```

25

26

## Core Imports

27

28

```java

29

import org.junit.jupiter.api.*;

30

import org.junit.jupiter.params.ParameterizedTest;

31

import org.junit.jupiter.params.provider.*;

32

```

33

34

Common static imports for assertions:

35

36

```java

37

import static org.junit.jupiter.api.Assertions.*;

38

import static org.junit.jupiter.api.Assumptions.*;

39

```

40

41

## Basic Usage

42

43

```java

44

import org.junit.jupiter.api.*;

45

import static org.junit.jupiter.api.Assertions.*;

46

47

class CalculatorTest {

48

49

@Test

50

@DisplayName("Addition should work correctly")

51

void testAddition() {

52

Calculator calc = new Calculator();

53

assertEquals(5, calc.add(2, 3));

54

assertNotNull(calc);

55

}

56

57

@BeforeEach

58

void setUp() {

59

// Setup before each test

60

System.out.println("Setting up test");

61

}

62

63

@AfterEach

64

void tearDown() {

65

// Cleanup after each test

66

System.out.println("Cleaning up test");

67

}

68

69

@ParameterizedTest

70

@ValueSource(ints = {1, 2, 3, 4, 5})

71

void testMultipleValues(int value) {

72

assertTrue(value > 0);

73

}

74

}

75

```

76

77

## Architecture

78

79

JUnit Jupiter is built around several key components:

80

81

- **Test API**: Core annotations and interfaces for writing tests (`@Test`, `@BeforeEach`, etc.)

82

- **Assertion Engine**: Comprehensive assertion methods with descriptive failure messages

83

- **Extension Model**: Powerful extension system for custom behavior and integrations

84

- **Test Engine**: Runtime execution engine that discovers and runs tests

85

- **Parameter Resolution**: Dependency injection system for test methods and constructors

86

- **Conditional Execution**: Rich set of conditions for enabling/disabling tests based on environment

87

88

## Capabilities

89

90

### Core Testing API

91

92

Essential testing annotations, lifecycle methods, and basic test structure. Provides the foundation for writing JUnit 5 tests with modern Java features.

93

94

```java { .api }

95

@Test

96

@BeforeAll

97

@BeforeEach

98

@AfterEach

99

@AfterAll

100

@DisplayName(String value)

101

@Nested

102

@Disabled(String reason)

103

@Timeout(long value, TimeUnit unit)

104

```

105

106

[Core Testing](./core-testing.md)

107

108

### Assertions and Assumptions

109

110

Comprehensive assertion methods for verifying test conditions and conditional test execution based on assumptions.

111

112

```java { .api }

113

// Core assertions

114

static void assertEquals(Object expected, Object actual);

115

static void assertTrue(boolean condition);

116

static void assertThrows(Class<T> expectedType, Executable executable);

117

static void assertAll(Executable... executables);

118

119

// Assumptions

120

static void assumeTrue(boolean assumption);

121

static void assumingThat(boolean assumption, Executable executable);

122

```

123

124

[Assertions and Assumptions](./assertions.md)

125

126

### Parameterized Tests

127

128

Advanced parameterized testing with multiple data sources, argument conversion, and aggregation for data-driven test scenarios.

129

130

```java { .api }

131

@ParameterizedTest

132

@ValueSource(ints = {1, 2, 3})

133

@CsvSource({"1,John", "2,Jane"})

134

@MethodSource("argumentProvider")

135

void parameterizedTest(int value, String name);

136

```

137

138

[Parameterized Tests](./parameterized-tests.md)

139

140

### Extensions and Lifecycle

141

142

Powerful extension model for customizing test behavior, dependency injection, and integrating with external frameworks.

143

144

```java { .api }

145

@ExtendWith(MyExtension.class)

146

@RegisterExtension

147

static MyExtension extension = new MyExtension();

148

149

interface Extension { }

150

interface BeforeAllCallback extends Extension;

151

interface ParameterResolver extends Extension;

152

```

153

154

[Extensions](./extensions.md)

155

156

### Conditional Execution

157

158

Rich set of conditions for controlling test execution based on operating system, JRE version, system properties, and custom conditions.

159

160

```java { .api }

161

@EnabledOnOs(OS.LINUX)

162

@DisabledOnJre(JRE.JAVA_8)

163

@EnabledIfSystemProperty(named = "env", matches = "prod")

164

@EnabledIf("customCondition")

165

```

166

167

[Conditional Execution](./conditional-execution.md)

168

169

### Dynamic Tests

170

171

Runtime test generation and nested test organization for complex test scenarios and hierarchical test structure.

172

173

```java { .api }

174

@TestFactory

175

Stream<DynamicTest> dynamicTests();

176

177

static DynamicTest dynamicTest(String displayName, Executable executable);

178

static DynamicContainer dynamicContainer(String displayName, Stream<DynamicNode> children);

179

```

180

181

[Dynamic Tests](./dynamic-tests.md)

182

183

### Parallel Execution and Resource Management

184

185

Configuration for parallel test execution, resource locking, and temporary file management for performance optimization.

186

187

```java { .api }

188

@Execution(ExecutionMode.CONCURRENT)

189

@ResourceLock("database")

190

@TempDir

191

Path tempDirectory;

192

```

193

194

[Parallel Execution](./parallel-execution.md)

195

196

## Types

197

198

### Core Test Interfaces

199

200

```java { .api }

201

interface TestInfo {

202

String getDisplayName();

203

Set<String> getTags();

204

Optional<Class<?>> getTestClass();

205

Optional<Method> getTestMethod();

206

}

207

208

interface TestReporter {

209

void publishEntry(Map<String, String> map);

210

void publishEntry(String key, String value);

211

}

212

213

interface RepetitionInfo {

214

int getCurrentRepetition();

215

int getTotalRepetitions();

216

}

217

```

218

219

### Assertion Utilities

220

221

```java { .api }

222

class AssertionFailureBuilder {

223

static AssertionFailureBuilder assertionFailure();

224

AssertionFailureBuilder message(String message);

225

AssertionFailureBuilder expected(Object expected);

226

AssertionFailureBuilder actual(Object actual);

227

AssertionFailedError build();

228

}

229

```

230

231

### Functional Interfaces

232

233

```java { .api }

234

@FunctionalInterface

235

interface Executable {

236

void execute() throws Throwable;

237

}

238

239

@FunctionalInterface

240

interface ThrowingSupplier<T> {

241

T get() throws Throwable;

242

}

243

244

@FunctionalInterface

245

interface ThrowingConsumer<T> {

246

void accept(T t) throws Throwable;

247

}

248

```