Class OutputCaptureRule

java.lang.Object
org.springframework.boot.test.system.OutputCaptureRule
All Implemented Interfaces:
CharSequence, org.junit.rules.TestRule, CapturedOutput

@Deprecated(since="4.0.0", forRemoval=true) public class OutputCaptureRule extends Object implements org.junit.rules.TestRule, CapturedOutput
Deprecated, for removal: This API element is subject to removal in a future version.
since 4.0.0 in favor of JUnit 5 and OutputCaptureExtension
JUnit @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");
    }

}
Since:
2.2.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.junit.runners.model.Statement
    apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    void
    expect(org.hamcrest.Matcher<? super String> matcher)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Verify that the output is matched by the supplied matcher.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return all content (both System.out and System.err) in the order that it was captured.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return System.err content in the order that it was captured.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return System.out content in the order that it was captured.
    Deprecated, for removal: This API element is subject to removal in a future version.
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface CapturedOutput

    charAt, length, subSequence

    Methods inherited from interface CharSequence

    chars, codePoints, getChars, isEmpty
  • Constructor Details

    • OutputCaptureRule

      public OutputCaptureRule()
      Deprecated, for removal: This API element is subject to removal in a future version.
  • Method Details

    • apply

      public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      apply in interface org.junit.rules.TestRule
    • getAll

      public String getAll()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from interface: CapturedOutput
      Return all content (both System.out and System.err) in the order that it was captured.
      Specified by:
      getAll in interface CapturedOutput
      Returns:
      all captured output
    • getOut

      public String getOut()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from interface: CapturedOutput
      Return System.out content in the order that it was captured.
      Specified by:
      getOut in interface CapturedOutput
      Returns:
      System.out captured output
    • getErr

      public String getErr()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from interface: CapturedOutput
      Return System.err content in the order that it was captured.
      Specified by:
      getErr in interface CapturedOutput
      Returns:
      System.err captured output
    • toString

      public String toString()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
    • expect

      public void expect(org.hamcrest.Matcher<? super String> matcher)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Verify that the output is matched by the supplied matcher. Verification is performed after the test method has executed.
      Parameters:
      matcher - the matcher