org.springframework.boot.test.rule

Class OutputCapture

  • All Implemented Interfaces:
    org.junit.rules.TestRule


    public class OutputCapture
    extends Object
    implements org.junit.rules.TestRule
    JUnit @Rule to capture output from System.out and System.err.
    Since:
    1.4.0
    Author:
    Phillip Webb, Andy Wilkinson
    • Constructor Detail

      • OutputCapture

        public OutputCapture()
    • Method Detail

      • apply

        public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Specified by:
        apply in interface org.junit.rules.TestRule
      • captureOutput

        protected void captureOutput()
      • releaseOutput

        protected void releaseOutput()
      • reset

        public void reset()
        Discard all currently accumulated output.
      • flush

        public void flush()
      • expect

        public void expect(org.hamcrest.Matcher<? super String> matcher)
        Verify that the output is matched by the supplied matcher. Verification is performed after the test method has executed.
        Parameters:
        matcher - the matcher