mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge pull request #33419 from currenjin
* 33419: Polish "Add test for beforeEach of OutputExtension" Add test for beforeEach of OutputExtension Closes gh-33419
This commit is contained in:
commit
5b2b122398
@ -18,6 +18,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.BeforeEachCallback;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
@ -30,18 +31,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 +60,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