From 782914516b4355bc2b16fac8c682ed2dc323010f Mon Sep 17 00:00:00 2001 From: qibaoguang Date: Fri, 27 Feb 2015 21:26:35 +0800 Subject: [PATCH] Update 35.4.3. OutputCapture.md --- .../35.4.3. OutputCapture.md | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/IV. Spring Boot features/35.4.3. OutputCapture.md b/IV. Spring Boot features/35.4.3. OutputCapture.md index e69de29..4888751 100644 --- a/IV. Spring Boot features/35.4.3. OutputCapture.md +++ b/IV. Spring Boot features/35.4.3. OutputCapture.md @@ -0,0 +1,20 @@ +### 35.4.3. OutputCapture + +OutputCapture是一个JUnit Rule,用于捕获System.out和System.err输出。只需简单的将捕获声明为一个@Rule,并使用toString()断言: +```java +import org.junit.Rule; +import org.junit.Test; +import org.springframework.boot.test.OutputCapture; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +public class MyTest { +@Rule +public OutputCapture capture = new OutputCapture(); +@Test +public void testName() throws Exception { +System.out.println("Hello World!"); +assertThat(capture.toString(), containsString("World")); +} +} +```