public class OutputCaptureRule extends Object implements org.junit.rules.TestRule, CapturedOutput
@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");
}
}
| Constructor and Description |
|---|
OutputCaptureRule() |
| Modifier and Type | Method and Description |
|---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description) |
void |
expect(org.hamcrest.Matcher<? super String> matcher)
Verify that the output is matched by the supplied
matcher. |
String |
getAll()
Return all content (both
System.out and System.err) in the order that it was captured. |
String |
getErr()
Return
System.err content in the order that it was captured. |
String |
getOut()
Return
System.out content in the order that it was captured. |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcharAt, length, subSequencechars, codePointspublic org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description)
apply in interface org.junit.rules.TestRulepublic String getAll()
CapturedOutputSystem.out and System.err) in the order that it was captured.getAll in interface CapturedOutputpublic String getOut()
CapturedOutputSystem.out content in the order that it was captured.getOut in interface CapturedOutputSystem.out captured outputpublic String getErr()
CapturedOutputSystem.err content in the order that it was captured.getErr in interface CapturedOutputSystem.err captured outputpublic String toString()
toString in interface CharSequencetoString in class Objectpublic void expect(org.hamcrest.Matcher<? super String> matcher)
matcher. Verification is
performed after the test method has executed.matcher - the matcher