@@ -7129,7 +7129,6 @@ that class explicitly where it is required, as shown in the following example:
7129
7129
7130
7130
[source,java,indent=0]
7131
7131
----
7132
- @RunWith(SpringRunner.class)
7133
7132
@SpringBootTest
7134
7133
@Import(MyTestsConfiguration.class)
7135
7134
public class MyTests {
@@ -7978,7 +7977,6 @@ The specific beans that you want to test should be specified by using the `value
7978
7977
7979
7978
[source,java,indent=0]
7980
7979
----
7981
- @RunWith(SpringRunner.class)
7982
7980
@RestClientTest(RemoteVehicleDetailsService.class)
7983
7981
public class ExampleRestClientTest {
7984
7982
@@ -8300,27 +8298,26 @@ which auto-configures one for you.
8300
8298
[[boot-features-output-capture-test-utility]]
8301
8299
==== OutputCapture
8302
8300
`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:
8305
8303
8306
8304
[source,java,indent=0]
8307
8305
----
8308
8306
import org.junit.jupiter.api.Test;
8309
- import org.junit.jupiter.api.extension.RegisterExtension ;
8307
+ import org.junit.jupiter.api.extension.ExtendWith ;
8310
8308
8311
- import org.springframework.boot.test.extension.OutputCapture;
8309
+ import org.springframework.boot.test.system.CapturedOutput;
8310
+ import org.springframework.boot.test.system.OutputCaptureExtension;
8312
8311
8313
8312
import static org.assertj.core.api.Assertions.assertThat;
8314
8313
8314
+ @ExtendWith(OutputCaptureExtension.class)
8315
8315
class MyTest {
8316
8316
8317
- @RegisterExtension
8318
- public OutputCapture output = new OutputCapture();
8319
-
8320
8317
@Test
8321
- void testName() {
8318
+ void testName(CapturedOutput output ) {
8322
8319
System.out.println("Hello World!");
8323
- assertThat(this. output.toString() ).contains("World"));
8320
+ assertThat(output).contains("World"));
8324
8321
}
8325
8322
8326
8323
}
0 commit comments