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 an instance ofSoftAssertionsorBDDSoftAssertionsinto test methods.Applicability
In this context, the term "test method" refers to any method annotated with
@Test,@RepeatedTest,@ParameterizedTest,@TestFactory, or@TestTemplate.
This extension does not injectSoftAssertionsorBDDSoftAssertionsarguments into test constructors or lifecycle methods.Scope
The scope of the
SoftAssertionsorBDDSoftAssertionsinstance managed by this extension begins when a parameter of typeSoftAssertionsorBDDSoftAssertionsis 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.NamespaceSOFT_ASSERTIONS_EXTENSION_NAMESPACE
-
Constructor Summary
Constructors Constructor Description SoftAssertionsExtension()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterTestExecution(org.junit.jupiter.api.extension.ExtensionContext extensionContext)private static <T> voidassertAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext, Class<T> type, Consumer<T> assertAll)private static org.junit.jupiter.api.extension.ExtensionContext.StoregetStore(org.junit.jupiter.api.extension.ExtensionContext extensionContext)private static booleanisUnsupportedParameterType(Parameter parameter)ObjectresolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)booleansupportsParameter(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:
supportsParameterin 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:
resolveParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver
-
afterTestExecution
public void afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
- Specified by:
afterTestExecutionin interfaceorg.junit.jupiter.api.extension.AfterTestExecutionCallback
-
assertAll
private static <T> void assertAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext, Class<T> type, Consumer<T> assertAll)
-
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)
-
-