Class OutputCaptureRule
java.lang.Object
org.springframework.boot.test.system.OutputCaptureRule
- All Implemented Interfaces:
CharSequence,org.junit.rules.TestRule,CapturedOutput
JUnit
@Rule to capture output from System.out and System.err.
To use add as a @Rule:
public class MyTest {
@Rule
public OutputCaptureRule output = new OutputCaptureRule();
@Test
public void test() {
assertThat(output).contains("ok");
}
}
- Since:
- 2.2.0
- Author:
- Phillip Webb, Andy Wilkinson
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.junit.runners.model.Statementapply(org.junit.runners.model.Statement base, org.junit.runner.Description description) voidVerify that the output is matched by the suppliedmatcher.getAll()Return all content (bothSystem.outandSystem.err) in the order that it was captured.getErr()ReturnSystem.errcontent in the order that it was captured.getOut()ReturnSystem.outcontent in the order that it was captured.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.boot.test.system.CapturedOutput
charAt, length, subSequenceMethods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Constructor Details
-
OutputCaptureRule
public OutputCaptureRule()
-
-
Method Details
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description) - Specified by:
applyin interfaceorg.junit.rules.TestRule
-
getAll
Description copied from interface:CapturedOutputReturn all content (bothSystem.outandSystem.err) in the order that it was captured.- Specified by:
getAllin interfaceCapturedOutput- Returns:
- all captured output
-
getOut
Description copied from interface:CapturedOutputReturnSystem.outcontent in the order that it was captured.- Specified by:
getOutin interfaceCapturedOutput- Returns:
System.outcaptured output
-
getErr
Description copied from interface:CapturedOutputReturnSystem.errcontent in the order that it was captured.- Specified by:
getErrin interfaceCapturedOutput- Returns:
System.errcaptured output
-
toString
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
expect
Verify that the output is matched by the suppliedmatcher. Verification is performed after the test method has executed.- Parameters:
matcher- the matcher
-