Update examples in documentation in accordance with JUnit 5

See gh-17096
This commit is contained in:
Madhura Bhave
2019-06-12 17:35:32 -07:00
parent 1213654c74
commit b59dc5bce4

View File

@@ -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"));
}
}