From b59dc5bce4a9709083dd358a43e4a7b1d3172994 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Wed, 12 Jun 2019 17:35:32 -0700 Subject: [PATCH] Update examples in documentation in accordance with JUnit 5 See gh-17096 --- .../main/asciidoc/spring-boot-features.adoc | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index b5490e5e02..8d0fab5bc3 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -7129,7 +7129,6 @@ that class explicitly where it is required, as shown in the following example: [source,java,indent=0] ---- - @RunWith(SpringRunner.class) @SpringBootTest @Import(MyTestsConfiguration.class) public class MyTests { @@ -7978,7 +7977,6 @@ The specific beans that you want to test should be specified by using the `value [source,java,indent=0] ---- - @RunWith(SpringRunner.class) @RestClientTest(RemoteVehicleDetailsService.class) public class ExampleRestClientTest { @@ -8300,27 +8298,26 @@ which auto-configures one for you. [[boot-features-output-capture-test-utility]] ==== OutputCapture `OutputCapture` is a JUnit `Extension` that you can use to capture `System.out` and -`System.err` output. You can declare the capture as a `@RegisterExtension` and then use -`toString()` for assertions, as follows: +`System.err` output. To use with {@link ExtendWith @ExtendWith}, you can inject +`CapturedOutput` as an argument to your test class constructor or test method as follows: [source,java,indent=0] ---- import org.junit.jupiter.api.Test; - import org.junit.jupiter.api.extension.RegisterExtension; + import org.junit.jupiter.api.extension.ExtendWith; - import org.springframework.boot.test.extension.OutputCapture; + import org.springframework.boot.test.system.CapturedOutput; + import org.springframework.boot.test.system.OutputCaptureExtension; import static org.assertj.core.api.Assertions.assertThat; + @ExtendWith(OutputCaptureExtension.class) class MyTest { - @RegisterExtension - public OutputCapture output = new OutputCapture(); - @Test - void testName() { + void testName(CapturedOutput output) { System.out.println("Hello World!"); - assertThat(this.output.toString()).contains("World")); + assertThat(output).contains("World")); } }