-
Deprecated ClassesClassDescriptionPlease use
SystemOutRule
.The
StandardOutputStreamLog
records writes to the standard output stream. The text written is available viaStandardOutputStreamLog.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()); }
Prevent output to the standard output stream
In general it is not necessary that a test writes to the standard output stream. Avoiding this output may speed up the test and reduce the clutter on the commandline.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);
-
Deprecated Enum ClassesEnum ClassDescriptionThis enum is no longer needed, because all rules that are using it have been replaced with rules that don't need the enum.
Mode of the
StandardErrorStreamLog
and theStandardOutputStreamLog
.
-
Deprecated MethodsMethodDescriptionPlease use
RestoreSystemProperties
along withSystem.clearProperty(String)
.Please useRestoreSystemProperties
along withSystem.setProperty(String, String)
.Simply remove all calls to this method.RestoreSystemProperties
restores all properties automatically. That's why you don't have to add the properties anymore.Please useSystemErrRule.clearLog()
.Clears the log. The log can be used again.
Please useSystemErrRule.getLog()
.Returns the text written to the standard error stream.
Please useSystemOutRule.clearLog()
.Clears the log. The log can be used again.
Please useSystemOutRule.getLog()
.Returns the text written to the standard output stream.
-
Deprecated ConstructorsConstructorDescriptionPlease use
RestoreSystemProperties()
. The rule restores all properties. That's why you don't have to specify the properties anymore.Please usenew SystemErrRule().enableLog()
.Creates a rule that records writes while they are still written to the standard error stream.
Please usenew SystemErrRule().enableLog()
instead ofnew StandardErrorStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM)
ornew SystemErrRule().enableLog()
.mute()
instead ofnew StandardErrorStreamLog(LogMode.LOG_ONLY)
.Creates a rule that records writes to the standard error stream according to the specified
LogMode
.Please usenew SystemOutRule().enableLog()
.Creates a rule that records writes while they are still written to the standard output stream.
Please usenew SystemOutRule().enableLog()
instead ofnew StandardOutputStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM)
ornew SystemOutRule().enableLog()
.mute()
instead ofnew StandardOutputStreamLog(LogMode.LOG_ONLY)
.Creates a rule that records writes to the standard output stream according to the specified
LogMode
.
-
Deprecated Enum ConstantsEnum ConstantDescriptionPlease use
SystemErrRule.enableLog()
orSystemOutRule.enableLog()
.Record the writes while they are still written to the stream.
Please useSystemErrRule.enableLog()
.mute()
orSystemOutRule.enableLog()
.mute()
.Capture the writes to the stream. Nothing is written to the stream itself.
SystemErrRule
.The
You can clear the log if you only want to test parts of the text written to the standard error stream.StandardErrorStreamLog
records writes to the standard error stream. The text written is available viaStandardErrorStreamLog.getLog()
.Prevent output to the standard error stream
In general it is not necessary that a test writes to the standard error stream. Avoiding this output may speed up the test and reduce the clutter on the commandline.The test does not write to the stream if the rule is created with the
LogMode.LOG_ONLY
mode.