mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Add test for beforeEach of OutputExtension
See gh-33419
This commit is contained in:
parent
06c6dafee2
commit
5f532a40f9
@ -17,9 +17,7 @@
|
||||
package org.springframework.boot.test.system;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.BeforeAllCallback;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.api.extension.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ -30,18 +28,24 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
@ExtendWith(OutputExtensionExtendWithTests.BeforeAllExtension.class)
|
||||
@ExtendWith(OutputExtensionExtendWithTests.BeforeEachExtension.class)
|
||||
class OutputExtensionExtendWithTests {
|
||||
|
||||
@Test
|
||||
void captureShouldReturnOutputCapturedBeforeTestMethod(CapturedOutput output) {
|
||||
void captureShouldReturnOutputCapturedBeforeAllTestMethod(CapturedOutput output) {
|
||||
assertThat(output).contains("Before all").doesNotContain("Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
void captureShouldReturnOutputCapturedBeforeEachTestMethod(CapturedOutput output) {
|
||||
assertThat(output).contains("Before each").doesNotContain("Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
void captureShouldReturnAllCapturedOutput(CapturedOutput output) {
|
||||
System.out.println("Hello World");
|
||||
System.err.println("Error!!!");
|
||||
assertThat(output).contains("Before all").contains("Hello World").contains("Error!!!");
|
||||
assertThat(output).contains("Before all").contains("Before each").contains("Hello World").contains("Error!!!");
|
||||
}
|
||||
|
||||
static class BeforeAllExtension implements BeforeAllCallback {
|
||||
@ -53,4 +57,13 @@ class OutputExtensionExtendWithTests {
|
||||
|
||||
}
|
||||
|
||||
static class BeforeEachExtension implements BeforeEachCallback {
|
||||
|
||||
@Override
|
||||
public void beforeEach(ExtensionContext context) {
|
||||
System.out.println("Before each");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user