Class HelidonJunitExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback
,org.junit.jupiter.api.extension.BeforeAllCallback
,org.junit.jupiter.api.extension.BeforeEachCallback
,org.junit.jupiter.api.extension.Extension
,org.junit.jupiter.api.extension.InvocationInterceptor
,org.junit.jupiter.api.extension.ParameterResolver
,org.junit.jupiter.api.extension.TestInstanceFactory
This extension starts a CDI container and adds the test class as a bean with support for injection. The test class uses
a CDI scope that follows the test lifecycle as defined by TestInstance
.
The container is started lazily during test execution to ensure that it is started after all other extensions.
The container can be customized with the following annotations:
HelidonTest.resetPerTest()
force a new CDI container per testDisableDiscovery
disables CDI discoveryAddBean
add CDI beansAddExtension
add CDI extensionAddJaxRs
add JAX-RS (Jersey)
The configuration can be customized with the following annotations:
Configuration
global setting for MicroProfile configurationAddConfig
declarative key/value pair configurationAddConfigBlock
declarative fragment configurationAddConfigSource
programmatic configuration
See also Socket
, a CDI qualifier to inject JAX-RS client or URI.
The container is created per test class by default, unless
HelidonTest.resetPerTest()
is true
, in
which case the container is created per test method.
The container and the configuration can be customized per method regardless of the value of
HelidonTest.resetPerTest()
. The container will be reset accordingly.
It is not recommended to provide a beans.xml
along the test classes, as it would combine beans from all tests.
Instead, you should use AddBean
to specify the beans per test or method.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor
org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
beforeEach
(org.junit.jupiter.api.extension.ExtensionContext context) createTestInstance
(org.junit.jupiter.api.extension.TestInstanceFactoryContext fc, org.junit.jupiter.api.extension.ExtensionContext ctx) void
interceptAfterEachMethod
(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> ic, org.junit.jupiter.api.extension.ExtensionContext ctx) void
interceptBeforeEachMethod
(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> ic, org.junit.jupiter.api.extension.ExtensionContext ctx) resolveParameter
(org.junit.jupiter.api.extension.ParameterContext pc, org.junit.jupiter.api.extension.ExtensionContext ctx) boolean
supportsParameter
(org.junit.jupiter.api.extension.ParameterContext pc, org.junit.jupiter.api.extension.ExtensionContext ctx) Methods inherited from class io.helidon.testing.junit5.TestJunitExtension
afterAll, beforeAll, initStaticContext, initStaticContext, interceptAfterAllMethod, interceptBeforeAllMethod, interceptDynamicTest, interceptTestClassConstructor, interceptTestFactoryMethod, interceptTestMethod, interceptTestTemplateMethod, invoke, run, runChecked, staticContext, store, storeLookup, supply, supplyChecked
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor
interceptAfterAllMethod, interceptBeforeAllMethod, interceptDynamicTest, interceptDynamicTest, interceptTestClassConstructor, interceptTestFactoryMethod, interceptTestMethod, interceptTestTemplateMethod
-
Constructor Details
-
HelidonJunitExtension
public HelidonJunitExtension()
-
-
Method Details
-
createTestInstance
public Object createTestInstance(org.junit.jupiter.api.extension.TestInstanceFactoryContext fc, org.junit.jupiter.api.extension.ExtensionContext ctx) - Specified by:
createTestInstance
in interfaceorg.junit.jupiter.api.extension.TestInstanceFactory
-
interceptBeforeEachMethod
public void interceptBeforeEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> ic, org.junit.jupiter.api.extension.ExtensionContext ctx) throws Throwable - Specified by:
interceptBeforeEachMethod
in interfaceorg.junit.jupiter.api.extension.InvocationInterceptor
- Overrides:
interceptBeforeEachMethod
in classTestJunitExtension
- Throws:
Throwable
-
interceptAfterEachMethod
public void interceptAfterEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> ic, org.junit.jupiter.api.extension.ExtensionContext ctx) throws Throwable - Specified by:
interceptAfterEachMethod
in interfaceorg.junit.jupiter.api.extension.InvocationInterceptor
- Overrides:
interceptAfterEachMethod
in classTestJunitExtension
- Throws:
Throwable
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
beforeEach
in interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext pc, org.junit.jupiter.api.extension.ExtensionContext ctx) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
supportsParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
- Overrides:
supportsParameter
in classTestJunitExtension
- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext pc, org.junit.jupiter.api.extension.ExtensionContext ctx) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
resolveParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
- Overrides:
resolveParameter
in classTestJunitExtension
- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-