Class SoftAssertionsExtension
- java.lang.Object
-
- org.assertj.core.api.junit.jupiter.SoftAssertionsExtension
-
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterTestExecutionCallback
,org.junit.jupiter.api.extension.Extension
,org.junit.jupiter.api.extension.ParameterResolver
public class SoftAssertionsExtension extends Object implements org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.AfterTestExecutionCallback
Extension for JUnit Jupiter that provides support for injecting a concrete implementation ofSoftAssertionsProvider
into test methods. Two examples that come packaged with AssertJ areSoftAssertions
andBDDSoftAssertions
, but custom implementations are also supported as long as they have a default constructor.Applicability
In this context, the term "test method" refers to any method annotated with
@Test
,@RepeatedTest
,@ParameterizedTest
,@TestFactory
, or@TestTemplate
.
This extension does not injectSoftAssertionsProvider
arguments into test constructors or lifecycle methods.Scope
The scope of the
SoftAssertionsProvider
instance managed by this extension begins when a parameter of typeSoftAssertionsProvider
is resolved for a test method.
The scope of the instance ends after the test method has been executed, this is whenassertAll()
will be invoked on the instance to verify that no soft assertions failed.Example with
SoftAssertions
@ExtendWith(SoftAssertionsExtension.class) class ExampleTestCase { @Test void multipleFailures(SoftAssertions softly) { softly.assertThat(2 * 3).isEqualTo(0); softly.assertThat(Arrays.asList(1, 2)).containsOnly(1); softly.assertThat(1 + 1).isEqualTo(2); } }
Example with
BDDSoftAssertions
@ExtendWith(SoftAssertionsExtension.class) class ExampleTestCase { @Test void multipleFailures(BDDSoftAssertions softly) { softly.then(2 * 3).isEqualTo(0); softly.then(Arrays.asList(1, 2)).containsOnly(1); softly.then(1 + 1).isEqualTo(2); } }
- Since:
- 3.13
- Author:
- Sam Brannen
-
-
Field Summary
Fields Modifier and Type Field Description private static org.junit.jupiter.api.extension.ExtensionContext.Namespace
SOFT_ASSERTIONS_EXTENSION_NAMESPACE
-
Constructor Summary
Constructors Constructor Description SoftAssertionsExtension()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
private static org.junit.jupiter.api.extension.ExtensionContext.Store
getStore(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
private static boolean
isUnsupportedParameterType(Parameter parameter)
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)
-
-
-
Method Detail
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
- Specified by:
supportsParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
- Specified by:
resolveParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
-
afterTestExecution
public void afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
- Specified by:
afterTestExecution
in interfaceorg.junit.jupiter.api.extension.AfterTestExecutionCallback
-
isUnsupportedParameterType
private static boolean isUnsupportedParameterType(Parameter parameter)
-
getStore
private static org.junit.jupiter.api.extension.ExtensionContext.Store getStore(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
-
-