public class OutputCaptureExtension extends Object implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.ParameterResolver
@Extension
to capture System.out
and
System.err
. Can be used on a test class via
@ExtendWith
. This extension provides parameter resolution
for a CapturedOutput
instance which can be used to assert
that the correct output was written.
To use with @ExtendWith
, inject the CapturedOutput
as an
argument to your test class constructor or test method:
@ExtendWith(OutputCaptureExtension.class) class MyTest { @Test void test(CapturedOutput output) { assertThat(output).contains("ok"); } }
CapturedOutput
Modifier and Type | Method and Description |
---|---|
void |
afterAll(org.junit.jupiter.api.extension.ExtensionContext context) |
void |
afterEach(org.junit.jupiter.api.extension.ExtensionContext context) |
void |
beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) |
void |
beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) |
Object |
resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext,
org.junit.jupiter.api.extension.ExtensionContext extensionContext) |
boolean |
supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext,
org.junit.jupiter.api.extension.ExtensionContext extensionContext) |
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
beforeAll
in interface org.junit.jupiter.api.extension.BeforeAllCallback
Exception
public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
afterAll
in interface org.junit.jupiter.api.extension.AfterAllCallback
Exception
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
beforeEach
in interface org.junit.jupiter.api.extension.BeforeEachCallback
Exception
public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
afterEach
in interface org.junit.jupiter.api.extension.AfterEachCallback
Exception
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException
supportsParameter
in interface org.junit.jupiter.api.extension.ParameterResolver
org.junit.jupiter.api.extension.ParameterResolutionException
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException
resolveParameter
in interface org.junit.jupiter.api.extension.ParameterResolver
org.junit.jupiter.api.extension.ParameterResolutionException
Copyright © 2019 Pivotal Software, Inc.. All rights reserved.