Skip to content

Commit b59dc5b

Browse files
committed
Update examples in documentation in accordance with JUnit 5
See gh-17096
1 parent 1213654 commit b59dc5b

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7129,7 +7129,6 @@ that class explicitly where it is required, as shown in the following example:
71297129

71307130
[source,java,indent=0]
71317131
----
7132-
@RunWith(SpringRunner.class)
71337132
@SpringBootTest
71347133
@Import(MyTestsConfiguration.class)
71357134
public class MyTests {
@@ -7978,7 +7977,6 @@ The specific beans that you want to test should be specified by using the `value
79787977

79797978
[source,java,indent=0]
79807979
----
7981-
@RunWith(SpringRunner.class)
79827980
@RestClientTest(RemoteVehicleDetailsService.class)
79837981
public class ExampleRestClientTest {
79847982
@@ -8300,27 +8298,26 @@ which auto-configures one for you.
83008298
[[boot-features-output-capture-test-utility]]
83018299
==== OutputCapture
83028300
`OutputCapture` is a JUnit `Extension` that you can use to capture `System.out` and
8303-
`System.err` output. You can declare the capture as a `@RegisterExtension` and then use
8304-
`toString()` for assertions, as follows:
8301+
`System.err` output. To use with {@link ExtendWith @ExtendWith}, you can inject
8302+
`CapturedOutput` as an argument to your test class constructor or test method as follows:
83058303

83068304
[source,java,indent=0]
83078305
----
83088306
import org.junit.jupiter.api.Test;
8309-
import org.junit.jupiter.api.extension.RegisterExtension;
8307+
import org.junit.jupiter.api.extension.ExtendWith;
83108308
8311-
import org.springframework.boot.test.extension.OutputCapture;
8309+
import org.springframework.boot.test.system.CapturedOutput;
8310+
import org.springframework.boot.test.system.OutputCaptureExtension;
83128311
83138312
import static org.assertj.core.api.Assertions.assertThat;
83148313
8314+
@ExtendWith(OutputCaptureExtension.class)
83158315
class MyTest {
83168316
8317-
@RegisterExtension
8318-
public OutputCapture output = new OutputCapture();
8319-
83208317
@Test
8321-
void testName() {
8318+
void testName(CapturedOutput output) {
83228319
System.out.println("Hello World!");
8323-
assertThat(this.output.toString()).contains("World"));
8320+
assertThat(output).contains("World"));
83248321
}
83258322
83268323
}

0 commit comments

Comments
 (0)