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