java.lang.Object
io.helidon.testing.junit5.TestJunitExtension
io.helidon.microprofile.testing.junit5.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

public class HelidonJunitExtension extends TestJunitExtension implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.TestInstanceFactory, org.junit.jupiter.api.extension.InvocationInterceptor, org.junit.jupiter.api.extension.ParameterResolver
A JUnit5 extension that integrates CDI with JUnit to support Helidon MP.

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:

The configuration can be customized with the following annotations:

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:
  • 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 interface org.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 interface org.junit.jupiter.api.extension.InvocationInterceptor
      Overrides:
      interceptBeforeEachMethod in class TestJunitExtension
      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 interface org.junit.jupiter.api.extension.InvocationInterceptor
      Overrides:
      interceptAfterEachMethod in class TestJunitExtension
      Throws:
      Throwable
    • beforeEach

      public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      beforeEach in interface org.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 interface org.junit.jupiter.api.extension.ParameterResolver
      Overrides:
      supportsParameter in class TestJunitExtension
      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 interface org.junit.jupiter.api.extension.ParameterResolver
      Overrides:
      resolveParameter in class TestJunitExtension
      Throws:
      org.junit.jupiter.api.extension.ParameterResolutionException