Class QuarkusComponentTestExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback,org.junit.jupiter.api.extension.AfterEachCallback,org.junit.jupiter.api.extension.BeforeAllCallback,org.junit.jupiter.api.extension.BeforeEachCallback,org.junit.jupiter.api.extension.Extension,org.junit.jupiter.api.extension.ParameterResolver,org.junit.jupiter.api.extension.TestInstancePostProcessor
QuarkusComponentTest or
programmatically with a static field of type QuarkusComponentTestExtension, annotated with RegisterExtension
and initialized with simplified constructor or using the builder.
Container lifecycle
This extension starts the CDI container and registers a dedicated SmallRyeConfig. If TestInstance.Lifecycle.PER_METHOD is used
(default) then the container is started during the before each test phase and stopped during the after each
test phase. However, if TestInstance.Lifecycle.PER_CLASS is used then the container is started during the before all test
phase and stopped during the after all test phase. The CDI request context is activated and terminated per each test
method.
Injection
Test class fields annotated with Inject and InjectMock are injected after a
test instance is created and unset before a test instance is destroyed. Dependent beans injected into these
fields are correctly destroyed before a test instance is destroyed.
Parameters of a test method for which a matching bean exists are resolved unless annotated with SkipInject. Dependent
beans injected into the test method arguments are correctly destroyed after the test method completes.
Auto Mocking Unsatisfied Dependencies
Unlike in regular CDI environments the test does not fail if a component injects an unsatisfied dependency. Instead, a
synthetic bean is registered automatically for each combination of required type and qualifiers of an injection point that
resolves to an unsatisfied dependency. The bean has the Singleton scope so it's shared across all injection points
with the same required type and qualifiers. The injected reference is an unconfigured Mockito mock. You can inject the mock
in your test using the InjectMock annotation and leverage the Mockito API to configure the behavior.
Custom Mocks For Unsatisfied Dependencies
Sometimes you need the full control over the bean attributes and maybe even configure the default mock behavior. You can use
the mock configurator API via the QuarkusComponentTestExtensionBuilder.mock(Class) method.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class -
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
ConstructorsConstructorDescriptionQuarkusComponentTestExtension(QuarkusComponentTestConfiguration baseConfiguration) QuarkusComponentTestExtension(Class<?>... additionalComponentClasses) The initial set of components under test is derived from the test class. -
Method Summary
Modifier and TypeMethodDescriptionvoidafterAll(org.junit.jupiter.api.extension.ExtensionContext context) voidafterEach(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) builder()(package private) static <T> T(package private) static booleanisTestMethod(Executable method) voidpostProcessTestInstance(Object testInstance, org.junit.jupiter.api.extension.ExtensionContext context) resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext context) booleansupportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
-
Field Details
-
BUILTIN_PARAMETER
-
-
Constructor Details
-
QuarkusComponentTestExtension
public QuarkusComponentTestExtension() -
QuarkusComponentTestExtension
The initial set of components under test is derived from the test class. The types of all fields annotated withInjectare considered the component types.- Parameters:
additionalComponentClasses-
-
QuarkusComponentTestExtension
QuarkusComponentTestExtension(QuarkusComponentTestConfiguration baseConfiguration)
-
-
Method Details
-
builder
-
beforeAll
- Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback- Throws:
Exception
-
afterAll
- Specified by:
afterAllin interfaceorg.junit.jupiter.api.extension.AfterAllCallback- Throws:
Exception
-
beforeEach
- Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback- Throws:
Exception
-
afterEach
- Specified by:
afterEachin interfaceorg.junit.jupiter.api.extension.AfterEachCallback- Throws:
Exception
-
postProcessTestInstance
public void postProcessTestInstance(Object testInstance, org.junit.jupiter.api.extension.ExtensionContext context) throws Exception - Specified by:
postProcessTestInstancein interfaceorg.junit.jupiter.api.extension.TestInstancePostProcessor- Throws:
Exception
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
supportsParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext context) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
resolveParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
cast
-
isTestMethod
-