0
# Testing Libraries
1
2
Testing frameworks, mocking libraries, and test containers with Spring Boot test integration. These libraries provide comprehensive testing capabilities for unit, integration, and end-to-end testing.
3
4
## Capabilities
5
6
### Core Testing Frameworks
7
8
Fundamental testing frameworks with managed versions and Spring integration.
9
10
```gradle { .api }
11
// JUnit Jupiter (JUnit 5)
12
'org.junit.jupiter:junit-jupiter' // 5.12.2
13
'org.junit.jupiter:junit-jupiter-api' // 5.12.2
14
'org.junit.jupiter:junit-jupiter-engine' // 5.12.2
15
'org.junit.jupiter:junit-jupiter-params' // 5.12.2
16
17
// JUnit Platform
18
'org.junit.platform:junit-platform-engine' // 1.11.3
19
'org.junit.platform:junit-platform-launcher' // 1.11.3
20
'org.junit.platform:junit-platform-commons' // 1.11.3
21
22
// JUnit 4 (legacy support)
23
'junit:junit' // 4.13.2
24
25
// TestNG alternative
26
// Note: TestNG not included in Spring Boot Dependencies BOM
27
```
28
29
### Mocking and Stubbing
30
31
Mocking frameworks for unit testing with dependency isolation.
32
33
```gradle { .api }
34
// Mockito
35
'org.mockito:mockito-core' // 5.15.0
36
'org.mockito:mockito-junit-jupiter' // 5.15.0
37
'org.mockito:mockito-inline' // 5.15.0
38
39
// Additional mocking utilities
40
'org.mockito:mockito-android' // 5.15.0
41
'org.mockito:mockito-errorprone' // 5.15.0
42
```
43
44
### Assertion Libraries
45
46
Fluent assertion libraries for readable test code.
47
48
```gradle { .api }
49
// AssertJ
50
'org.assertj:assertj-core' // 3.26.3
51
52
// Hamcrest matchers
53
'org.hamcrest:hamcrest' // 3.0
54
'org.hamcrest:hamcrest-core' // 3.0
55
'org.hamcrest:hamcrest-library' // 3.0
56
57
// JSON assertions
58
'org.skyscreamer:jsonassert' // 1.5.3
59
60
// XML assertions
61
'org.xmlunit:xmlunit-core' // 2.10.2
62
'org.xmlunit:xmlunit-matchers' // 2.10.2
63
'org.xmlunit:xmlunit-assertj' // 2.10.2
64
```
65
66
### Spring Boot Testing
67
68
Spring Boot-specific testing support and auto-configuration.
69
70
```gradle { .api }
71
// Spring Boot test starter (includes JUnit, Mockito, AssertJ, Spring Test)
72
'org.springframework.boot:spring-boot-starter-test' // 3.5.3
73
74
// Spring Boot test framework
75
'org.springframework.boot:spring-boot-test' // 3.5.3
76
'org.springframework.boot:spring-boot-test-autoconfigure' // 3.5.3
77
78
// Testcontainers integration
79
'org.springframework.boot:spring-boot-testcontainers' // 3.5.3
80
```
81
82
### Container Testing
83
84
Integration testing with real services using containers.
85
86
```gradle { .api }
87
// Testcontainers core
88
'org.testcontainers:testcontainers' // 1.21.2
89
'org.testcontainers:junit-jupiter' // 1.21.2
90
91
// Database containers
92
'org.testcontainers:postgresql' // 1.21.2
93
'org.testcontainers:mysql' // 1.21.2
94
'org.testcontainers:mariadb' // 1.21.2
95
'org.testcontainers:mssqlserver' // 1.21.2
96
'org.testcontainers:oracle-xe' // 1.21.2
97
'org.testcontainers:oracle-free' // 1.21.2
98
99
// NoSQL containers
100
'org.testcontainers:mongodb' // 1.21.2
101
'org.testcontainers:neo4j' // 1.21.2
102
'org.testcontainers:cassandra' // 1.21.2
103
'org.testcontainers:couchbase' // 1.21.2
104
'org.testcontainers:elasticsearch' // 1.21.2
105
'org.testcontainers:clickhouse' // 1.21.2
106
107
// Message broker containers
108
'org.testcontainers:kafka' // 1.21.2
109
'org.testcontainers:rabbitmq' // 1.21.2
110
'org.testcontainers:pulsar' // 1.21.2
111
'org.testcontainers:activemq' // 1.21.2
112
'org.testcontainers:redpanda' // 1.21.2
113
114
// Cache and data store containers
115
'com.redis:testcontainers-redis' // 2.2.4
116
'org.testcontainers:r2dbc' // 1.21.2
117
118
// Observability containers
119
'org.testcontainers:grafana' // 1.21.2
120
121
// JDBC URL support
122
'org.testcontainers:jdbc' // 1.21.2
123
```
124
125
### Web Testing
126
127
Web layer testing with mock servers and browser automation.
128
129
```gradle { .api }
130
// Spring MVC Test
131
'org.springframework:spring-test' // 6.2.8
132
133
// WebTestClient (for reactive web testing)
134
'org.springframework:spring-webflux' // 6.2.8
135
136
// REST API testing
137
'io.rest-assured:rest-assured' // 5.5.5
138
'io.rest-assured:json-path' // 5.5.5
139
'io.rest-assured:xml-path' // 5.5.5
140
'io.rest-assured:json-schema-validator' // 5.5.5
141
142
// Mock web server
143
'com.squareup.okhttp3:mockwebserver' // (managed via other dependencies)
144
145
// Headless browser testing
146
'org.htmlunit:htmlunit' // 4.11.1
147
148
// Selenium WebDriver
149
'org.seleniumhq.selenium:selenium-java' // 4.31.0
150
'org.seleniumhq.selenium:selenium-chrome-driver' // 4.31.0
151
'org.seleniumhq.selenium:selenium-firefox-driver' // 4.31.0
152
'org.seleniumhq.selenium:selenium-edge-driver' // 4.31.0
153
'org.seleniumhq.selenium:selenium-safari-driver' // 4.31.0
154
'org.seleniumhq.selenium:htmlunit3-driver' // 4.30.0
155
```
156
157
### Asynchronous Testing
158
159
Testing support for asynchronous and reactive code.
160
161
```gradle { .api }
162
// Awaitility (async testing utilities)
163
'org.awaitility:awaitility' // 4.2.2
164
'org.awaitility:awaitility-groovy' // 4.2.2
165
'org.awaitility:awaitility-kotlin' // 4.2.2
166
167
// Reactor Test
168
'io.projectreactor:reactor-test' // (managed via reactor-bom)
169
170
// Spring Test reactive support
171
'org.springframework:spring-webflux' // 6.2.8
172
```
173
174
### Framework-Specific Testing
175
176
Testing support for specific frameworks and technologies.
177
178
```gradle { .api }
179
// Spring Security testing
180
'org.springframework.security:spring-security-test' // 6.5.1
181
182
// Spring Data testing
183
'org.springframework.data:spring-data-commons' // 3.4.1
184
185
// Spring Batch testing
186
'org.springframework.batch:spring-batch-test' // 5.2.2
187
188
// Spring Integration testing
189
'org.springframework.integration:spring-integration-test' // 6.5.0
190
191
// Spring AMQP testing
192
'org.springframework.amqp:spring-rabbit-test' // 3.2.5
193
194
// Spring Kafka testing
195
'org.springframework.kafka:spring-kafka-test' // 3.3.7
196
197
// GraphQL testing
198
'org.springframework.graphql:spring-graphql-test' // 1.4.0
199
```
200
201
## Usage Examples
202
203
### Basic Unit Testing
204
205
```gradle
206
dependencies {
207
implementation platform('org.springframework.boot:spring-boot-dependencies:3.5.3')
208
209
implementation 'org.springframework.boot:spring-boot-starter'
210
211
testImplementation 'org.springframework.boot:spring-boot-starter-test'
212
// Includes: JUnit Jupiter, Mockito, AssertJ, Spring Test, JSONassert, Hamcrest
213
}
214
```
215
216
### Integration Testing with Testcontainers
217
218
```gradle
219
dependencies {
220
implementation platform('org.springframework.boot:spring-boot-dependencies:3.5.3')
221
222
implementation 'org.springframework.boot:spring-boot-starter-web'
223
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
224
225
testImplementation 'org.springframework.boot:spring-boot-starter-test'
226
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
227
testImplementation 'org.testcontainers:junit-jupiter'
228
testImplementation 'org.testcontainers:postgresql'
229
}
230
```
231
232
### Web Layer Testing
233
234
```gradle
235
dependencies {
236
implementation platform('org.springframework.boot:spring-boot-dependencies:3.5.3')
237
238
implementation 'org.springframework.boot:spring-boot-starter-web'
239
240
testImplementation 'org.springframework.boot:spring-boot-starter-test'
241
testImplementation 'io.rest-assured:rest-assured'
242
testImplementation 'org.htmlunit:htmlunit'
243
}
244
```
245
246
### Reactive Testing
247
248
```gradle
249
dependencies {
250
implementation platform('org.springframework.boot:spring-boot-dependencies:3.5.3')
251
252
implementation 'org.springframework.boot:spring-boot-starter-webflux'
253
implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
254
255
testImplementation 'org.springframework.boot:spring-boot-starter-test'
256
testImplementation 'io.projectreactor:reactor-test'
257
testImplementation 'org.awaitility:awaitility'
258
}
259
```
260
261
### Security Testing
262
263
```gradle
264
dependencies {
265
implementation platform('org.springframework.boot:spring-boot-dependencies:3.5.3')
266
267
implementation 'org.springframework.boot:spring-boot-starter-web'
268
implementation 'org.springframework.boot:spring-boot-starter-security'
269
270
testImplementation 'org.springframework.boot:spring-boot-starter-test'
271
testImplementation 'org.springframework.security:spring-security-test'
272
}
273
```
274
275
### Message Broker Testing
276
277
```gradle
278
dependencies {
279
implementation platform('org.springframework.boot:spring-boot-dependencies:3.5.3')
280
281
implementation 'org.springframework.boot:spring-boot-starter-amqp'
282
implementation 'org.springframework.kafka:spring-kafka'
283
284
testImplementation 'org.springframework.boot:spring-boot-starter-test'
285
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
286
testImplementation 'org.testcontainers:rabbitmq'
287
testImplementation 'org.testcontainers:kafka'
288
testImplementation 'org.springframework.amqp:spring-rabbit-test'
289
testImplementation 'org.springframework.kafka:spring-kafka-test'
290
}
291
```
292
293
### Browser Testing with Selenium
294
295
```gradle
296
dependencies {
297
implementation platform('org.springframework.boot:spring-boot-dependencies:3.5.3')
298
299
implementation 'org.springframework.boot:spring-boot-starter-web'
300
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
301
302
testImplementation 'org.springframework.boot:spring-boot-starter-test'
303
testImplementation 'org.seleniumhq.selenium:selenium-java'
304
testImplementation 'org.seleniumhq.selenium:selenium-chrome-driver'
305
testImplementation 'org.testcontainers:selenium'
306
}
307
```
308
309
### Multi-Database Testing
310
311
```gradle
312
dependencies {
313
implementation platform('org.springframework.boot:spring-boot-dependencies:3.5.3')
314
315
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
316
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
317
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
318
319
testImplementation 'org.springframework.boot:spring-boot-starter-test'
320
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
321
testImplementation 'org.testcontainers:junit-jupiter'
322
testImplementation 'org.testcontainers:postgresql'
323
testImplementation 'org.testcontainers:mongodb'
324
testImplementation 'com.redis:testcontainers-redis'
325
}
326
```