public class StandardErrorStreamLog extends PrintStreamLog
StandardErrorStreamLog records writes to the standard error
stream. The text written is available via PrintStreamLog.getLog().
public void MyTest {
@Rule
public final StandardErrorStreamLog log = new StandardErrorStreamLog();
@Test
public void captureErrorStream() {
System.err.print("hello world");
assertEquals("hello world", log.getLog());
}
}
You can clear the log if you only want to test parts of the text written to
the standard error stream.
@Test
public void captureErrorStream() {
System.err.print("before");
log.clear();
System.err.print("afterwards");
assertEquals("afterwards", log.getLog());
}
The test does not write to the stream if the rule is created with the
LogMode.LOG_ONLY mode.
@Rule public final StandardErrorStreamLog log = new StandardErrorStreamLog(LOG_ONLY);
| Constructor and Description |
|---|
StandardErrorStreamLog()
Creates a rule that records writes while they are still written to the
standard error stream.
|
StandardErrorStreamLog(LogMode mode)
Creates a rule that records writes to the standard error stream according
to the specified
LogMode. |
| Modifier and Type | Method and Description |
|---|---|
protected java.io.PrintStream |
getOriginalStream() |
protected void |
setStream(java.io.PrintStream wrappedLog) |
after, before, clear, getLogpublic StandardErrorStreamLog()
public StandardErrorStreamLog(LogMode mode)
LogMode.mode - how the rule handles writes to the standard error stream.java.lang.NullPointerException - if mode is null.protected java.io.PrintStream getOriginalStream()
getOriginalStream in class PrintStreamLogprotected void setStream(java.io.PrintStream wrappedLog)
setStream in class PrintStreamLogCopyright © 2011-2015. All Rights Reserved.