OutputCaptureRule

open class OutputCaptureRule : TestRule, CapturedOutput

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");
    }

}

Author

Phillip Webb

Andy Wilkinson

Since

2.2.0

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open fun apply(base: Statement, description: Description): Statement
Link copied to clipboard
abstract fun charAt(p: Int): Char
open fun charAt(index: Int): Char
Link copied to clipboard
open fun chars(): IntStream
Link copied to clipboard
open fun codePoints(): IntStream
Link copied to clipboard
open fun compare(cs1: CharSequence, cs2: CharSequence): Int
Link copied to clipboard
open fun expect(matcher: Matcher<in String>)
Verify that the output is matched by the supplied matcher.
Link copied to clipboard
open fun getAll(): String
Return all content (both System.out and System.err) in the order that it was captured.
Link copied to clipboard
open fun getErr(): String
Return System.err content in the order that it was captured.
Link copied to clipboard
open fun getOut(): String
Return System.out content in the order that it was captured.
Link copied to clipboard
open fun isEmpty(): Boolean
Link copied to clipboard
abstract fun length(): Int
open fun length(): Int
Link copied to clipboard
abstract fun subSequence(p: Int, p1: Int): CharSequence
open fun subSequence(start: Int, end: Int): CharSequence
Link copied to clipboard
open fun toString(): String