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, wait
charAt, length, subSequence
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
apply
in interface org.junit.rules.TestRule
public java.lang.String getAll()
CapturedOutput
System.out
and System.err
) in the order that it was captured.getAll
in interface CapturedOutput
public java.lang.String getOut()
CapturedOutput
System.out
content in the order that it was captured.getOut
in interface CapturedOutput
System.out
captured outputpublic java.lang.String getErr()
CapturedOutput
System.err
content in the order that it was captured.getErr
in interface CapturedOutput
System.err
captured outputpublic java.lang.String toString()
toString
in interface java.lang.CharSequence
toString
in class java.lang.Object
public void expect(org.hamcrest.Matcher<? super java.lang.String> matcher)
matcher
. Verification is
performed after the test method has executed.matcher
- the matcher