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. |
void |
reset()
Deprecated.
since 2.2.0 with no replacement
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
charAt, length, subSequence
chars, codePoints
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
@Deprecated public void reset()
public String getAll()
CapturedOutput
System.out
and System.err
) in the order that it was captured.getAll
in interface CapturedOutput
public String getOut()
CapturedOutput
System.out
content in the order that it was captured.getOut
in interface CapturedOutput
System.out
captured outputpublic String getErr()
CapturedOutput
System.err
content in the order that it was captured.getErr
in interface CapturedOutput
System.err
captured outputpublic String toString()
toString
in interface CharSequence
toString
in class Object
public void expect(org.hamcrest.Matcher<? super String> matcher)
matcher
. Verification is
performed after the test method has executed.matcher
- the matcherCopyright © 2019 Pivotal Software, Inc.. All rights reserved.