RestoreSystemProperties
restores all properties
automatically. That's why you don't have to add the properties
anymore.Assertion
encapsulates the code of an assertion into an object.SystemErrRule.clearLog()
.
Clears the log. The log can be used again.
SystemOutRule.clearLog()
.
Clears the log. The log can be used again.
RestoreSystemProperties
along with System.clearProperty(String)
.ClearSystemProperties
rule clears a set of system
properties when the test starts and restores their original values
when the test finishes (whether it passes or fails).ClearSystemProperties
rule that clears the specified
properties and restores their original values when the test finishes
(whether it passes or fails).DisallowWriteToSystemErr
lets a test fail if it tries to write
something to System.err
.DisallowWriteToSystemOut
lets a test fail if it tries to write
something to System.out
.System.err
.System.out
.EnvironmentVariables
rule allows you to set environment variables
for your test.ExpectedSystemExit
allows in-test specification of expected
System.exit(...)
calls.SystemErrRule.getLog()
.
Returns the text written to the standard error stream.
SystemOutRule.getLog()
.
Returns the text written to the standard output stream.
System.err
since
SystemErrRule.enableLog()
(respectively SystemErrRule.clearLog()
has been called.System.out
since
SystemOutRule.enableLog()
(respectively SystemOutRule.clearLog()
has been called.System.err
since
SystemErrRule.enableLog()
(respectively SystemErrRule.clearLog()
has been called.System.out
since
SystemOutRule.enableLog()
(respectively SystemOutRule.clearLog()
has been called.System.err
since
SystemErrRule.enableLog()
(respectively SystemErrRule.clearLog()
has been called.System.out
since
SystemOutRule.enableLog()
(respectively SystemOutRule.clearLog()
has been called.SystemErrRule.enableLog()
or
SystemOutRule.enableLog()
.
Record the writes while they are still written to the stream.
SystemErrRule.enableLog()
.mute()
or
SystemOutRule.enableLog()
.mute()
.
Capture the writes to the stream. Nothing is written to the stream itself.
Mode of the
StandardErrorStreamLog
and the
StandardOutputStreamLog
.
System.err
.System.out
.System.err
for successful tests only.System.out
for successful tests only.NoExitSecurityManager
throws a CheckExitCalled
exception
whenever NoExitSecurityManager.checkExit(int)
is called.System.in
.ProvideSecurityManager
rule provides an arbitrary security
manager to a test.ProvideSystemProperty
rule provides an arbitrary value for a
system property to a test.RestoreSystemProperties
rule undoes changes of system
properties when the test finishes (whether it passes or fails).RestoreSystemProperties
rule that restores all
system properties.RestoreSystemProperties()
. The
rule restores all properties. That's why you don't have to
specify the properties anymore.RestoreSystemProperties
along with System.setProperty(String, String)
.SystemErrRule
.
The StandardErrorStreamLog
records writes to the standard error
stream. The text written is available via StandardErrorStreamLog.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);
new SystemErrRule().enableLog()
.
Creates a rule that records writes while they are still written to the standard error stream.
new SystemErrRule().enableLog()
instead of
new StandardErrorStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM)
or
new SystemErrRule().enableLog()
.mute()
instead of new StandardErrorStreamLog(LogMode.LOG_ONLY)
.
Creates a rule that records writes to the standard error stream
according to the specified LogMode
.
SystemOutRule
.
The StandardOutputStreamLog
records writes to the standard output
stream. The text written is available via StandardOutputStreamLog.getLog()
.
public void MyTest { @Rule public final StandardOutputStreamLog log = new StandardOutputStreamLog(); @Test public void captureOutputStream() { System.out.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 output stream.
@Test public void captureOutputStream() { System.out.print("before"); log.clear(); System.out.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 StandardOutputStreamLog log = new StandardOutputStreamLog(LOG_ONLY);
new SystemOutRule().enableLog()
.
Creates a rule that records writes while they are still written to the standard output stream.
new SystemOutRule().enableLog()
instead of
new StandardOutputStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM)
or
new SystemOutRule().enableLog()
.mute()
instead of new StandardOutputStreamLog(LogMode.LOG_ONLY)
.
Creates a rule that records writes to the standard output stream
according to the specified LogMode
.
SystemErrRule
intercepts the writes to
System.err
.SystemOutRule
intercepts the writes to
System.out
.TextFromStandardInputStream
rule replaces System.in
with
another InputStream
, which provides an arbitrary text.IOException
that is thrown by System.in
.RuntimeException
that is thrown by System.in
.Copyright © 2011–2018. All rights reserved.