You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using JUnit 4, the first step in generating documentation snippets is to declare a `public` `JUnitRestDocumentation` field that is annotated as a JUnit `@Rule`.
213
+
When using JUnit 5, the first step in generating documentation snippets is to apply the `RestDocumentationExtension` to your test class.
213
214
The following example shows how to do so:
214
215
215
216
[source,java,indent=0]
216
217
----
217
-
@Rule
218
-
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation();
218
+
@ExtendWith(RestDocumentationExtension.class)
219
+
public class JUnit5ExampleTests {
219
220
----
220
221
221
-
By default, the `JUnitRestDocumentation` rule is automatically configured with an output directory based on your project's build tool:
222
+
When testing a typical Spring application, you should also apply the `SpringExtension`:
The `RestDocumentationExtension` is automatically configured with an output directory based on your project's build tool:
222
231
223
232
[cols="2,5"]
224
233
|===
@@ -231,38 +240,42 @@ By default, the `JUnitRestDocumentation` rule is automatically configured with a
231
240
| `build/generated-snippets`
232
241
|===
233
242
234
-
You can override the default by providing an output directory when you create the `JUnitRestDocumentation` instance.
243
+
If you are using JUnit 5.1, you can override the default by registering the extension as a field in your test class and providing an output directory when creating it.
235
244
The following example shows how to do so:
236
245
237
246
[source,java,indent=0]
238
247
----
239
-
@Rule
240
-
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("custom");
248
+
public class JUnit5ExampleTests {
249
+
250
+
@RegisterExtension
251
+
final RestDocumentationExtension restDocumentation = new RestDocumentationExtension ("custom");
252
+
253
+
}
241
254
----
242
255
243
-
Next, you must provide an `@Before` method to configure MockMvc or WebTestClient, or REST Assured.
244
-
The following examples show how to do so:
256
+
Next, you must provide a `@BeforeEach` method to configure MockMvc or WebTestClient, or REST Assured.
<1> The `MockMvc` instance is configured by using a `MockMvcRestDocumentationConfigurer`.
252
265
You can obtain an instance of this class from the static `documentationConfiguration()` method on `org.springframework.restdocs.mockmvc.MockMvcRestDocumentation`.
<1> The `WebTestClient` instance is configured by adding a `WebTestclientRestDocumentationConfigurer` as an `ExchangeFilterFunction`.
272
+
<1> The `WebTestClient` instance is configured by adding a `WebTestClientRestDocumentationConfigurer` as an `ExchangeFilterFunction`.
260
273
You can obtain an instance of this class from the static `documentationConfiguration()` method on `org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation`.
<1> REST Assured is configured by adding a `RestAssuredRestDocumentationConfigurer` as a `Filter`.
268
281
You can obtain an instance of this class from the static `documentationConfiguration()` method on `RestAssuredRestDocumentation` in the `org.springframework.restdocs.restassured` package.
@@ -272,27 +285,19 @@ See the <<configuration, configuration section>> for more information.
When using JUnit 5, the first step in generating documentation snippets is to apply the `RestDocumentationExtension` to your test class.
291
+
When using JUnit 4, the first step in generating documentation snippets is to declare a `public` `JUnitRestDocumentation` field that is annotated as a JUnit `@Rule`.
279
292
The following example shows how to do so:
280
293
281
294
[source,java,indent=0]
282
295
----
283
-
@ExtendWith(RestDocumentationExtension.class)
284
-
public class JUnit5ExampleTests {
285
-
----
286
-
287
-
When testing a typical Spring application, you should also apply the `SpringExtension`:
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation();
293
298
----
294
299
295
-
The `RestDocumentationExtension` is automatically configured with an output directory based on your project's build tool:
300
+
By default, the `JUnitRestDocumentation` rule is automatically configured with an output directory based on your project's build tool:
296
301
297
302
[cols="2,5"]
298
303
|===
@@ -305,42 +310,38 @@ The `RestDocumentationExtension` is automatically configured with an output dire
305
310
| `build/generated-snippets`
306
311
|===
307
312
308
-
If you are using JUnit 5.1, you can override the default by registering the extension as a field in your test class and providing an output directory when creating it.
313
+
You can override the default by providing an output directory when you create the `JUnitRestDocumentation` instance.
309
314
The following example shows how to do so:
310
315
311
316
[source,java,indent=0]
312
317
----
313
-
public class JUnit5ExampleTests {
314
-
315
-
@RegisterExtension
316
-
final RestDocumentationExtension restDocumentation = new RestDocumentationExtension ("custom");
317
-
318
-
}
318
+
@Rule
319
+
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("custom");
319
320
----
320
321
321
-
Next, you must provide a `@BeforeEach` method to configure MockMvc or WebTestClient, or REST Assured.
322
-
The following listings show how to do so:
322
+
Next, you must provide an `@Before` method to configure MockMvc or WebTestClient, or REST Assured.
<1> The `MockMvc` instance is configured by using a `MockMvcRestDocumentationConfigurer`.
330
331
You can obtain an instance of this class from the static `documentationConfiguration()` method on `org.springframework.restdocs.mockmvc.MockMvcRestDocumentation`.
<1> The `WebTestClient` instance is configured by adding a `WebTestClientRestDocumentationConfigurer` as an `ExchangeFilterFunction`.
338
+
<1> The `WebTestClient` instance is configured by adding a `WebTestclientRestDocumentationConfigurer` as an `ExchangeFilterFunction`.
338
339
You can obtain an instance of this class from the static `documentationConfiguration()` method on `org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation`.
<1> REST Assured is configured by adding a `RestAssuredRestDocumentationConfigurer` as a `Filter`.
346
347
You can obtain an instance of this class from the static `documentationConfiguration()` method on `RestAssuredRestDocumentation` in the `org.springframework.restdocs.restassured` package.
0 commit comments