Package io.micronaut.test.extensions
Class AbstractMicronautExtension<C>
java.lang.Object
io.micronaut.test.extensions.AbstractMicronautExtension<C>
- Type Parameters:
C- The extension context
- All Implemented Interfaces:
TestExecutionListener,TestMethodInterceptor<Object>
- Direct Known Subclasses:
MicronautJunit5Extension,MicronautSpockExtension
public abstract class AbstractMicronautExtension<C>
extends Object
implements TestExecutionListener, TestMethodInterceptor<Object>
Abstract base class for both JUnit 5 and Spock.
- Since:
- 1.0
- Author:
- graemerocher
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected io.micronaut.context.ApplicationContextstatic final Stringprotected io.micronaut.runtime.EmbeddedApplicationstatic final Stringprotected io.micronaut.runtime.context.scope.refresh.RefreshScopeprotected io.micronaut.inject.BeanDefinition<?>static final StringThe name of the property source that contains test properties.static final Stringstatic final Stringstatic final Stringprotected MicronautTestValue -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterClass(C context) Executed after the class is complete.voidafterCleanupTest(TestContext testContext) Executed after the setup method of a test method.voidExecuted after each test completes.voidafterSetupTest(TestContext testContext) Executed after the setup method of a test method.voidafterTestClass(TestContext testContext) Executed after all of the tests of a class have bean executed.voidafterTestExecution(TestContext testContext) Executed after a single test iteration has been executed .voidafterTestMethod(TestContext testContext) Executed after a test method has been executed (a test method may contain multiple iterations).protected abstract voidalignMocks(C context, Object instance) protected voidbeforeClass(C context, Class<?> testClass, @Nullable MicronautTestValue testAnnotationValue) Executed before tests within a class are run.voidbeforeCleanupTest(TestContext testContext) Executed before the setup method of a test method.protected voidbeforeEach(C context, @Nullable Object testInstance, @Nullable AnnotatedElement method, List<io.micronaut.context.annotation.Property> propertyAnnotations) To be called by the different implementations before each test method.voidbeforeSetupTest(TestContext testContext) Executed before the setup method of a test method.voidbeforeTestClass(TestContext testContext) Executed before all of the tests of a class are executed.voidbeforeTestExecution(TestContext testContext) Executed before a single test iteration is executed.voidbeforeTestMethod(TestContext testContext) Executed before a test method is executed (a test method may contain multiple iterations).protected booleaninterceptAfterEach(TestMethodInvocationContext<Object> methodInvocationContext) Intercepts after each test invocation.interceptBeforeEach(TestMethodInvocationContext<Object> methodInvocationContext) Intercepts before each test invocation.interceptTest(TestMethodInvocationContext<Object> methodInvocationContext) Intercepts each test invocation.protected booleanisTestSuiteBeanPresent(Class<?> requiredTestClass) protected voidpostProcessBuilder(io.micronaut.context.ApplicationContextBuilder builder) Allows subclasses to customize the builder right before context initialization.protected abstract voidresolveTestProperties(C context, MicronautTestValue testAnnotationValue, Map<String, Object> testProperties) Resolves any test properties.protected voidStarts the application context.
-
Field Details
-
TEST_ROLLBACK
- See Also:
-
TEST_TRANSACTIONAL
- See Also:
-
TEST_TRANSACTION_MODE
- See Also:
-
DISABLED_MESSAGE
- See Also:
-
MISCONFIGURED_MESSAGE
- See Also:
-
TEST_PROPERTY_SOURCE
The name of the property source that contains test properties.- See Also:
-
applicationContext
protected io.micronaut.context.ApplicationContext applicationContext -
embeddedApplication
protected io.micronaut.runtime.EmbeddedApplication embeddedApplication -
refreshScope
protected io.micronaut.runtime.context.scope.refresh.RefreshScope refreshScope -
specDefinition
protected io.micronaut.inject.BeanDefinition<?> specDefinition -
testProperties
-
oldValues
-
testAnnotationValue
-
-
Constructor Details
-
AbstractMicronautExtension
public AbstractMicronautExtension()
-
-
Method Details
-
hasInterceptors
protected boolean hasInterceptors()- Returns:
- True if there are interceptors
-
interceptBeforeEach
public Object interceptBeforeEach(TestMethodInvocationContext<Object> methodInvocationContext) throws Throwable Description copied from interface:TestMethodInterceptorIntercepts before each test invocation.- Specified by:
interceptBeforeEachin interfaceTestMethodInterceptor<C>- Parameters:
methodInvocationContext- the method invocation context- Returns:
- intercepted return value
- Throws:
Exception- allows any exception to propagateThrowable
-
interceptAfterEach
public Object interceptAfterEach(TestMethodInvocationContext<Object> methodInvocationContext) throws Throwable Description copied from interface:TestMethodInterceptorIntercepts after each test invocation.- Specified by:
interceptAfterEachin interfaceTestMethodInterceptor<C>- Parameters:
methodInvocationContext- the method invocation context- Returns:
- intercepted return value
- Throws:
Exception- allows any exception to propagateThrowable
-
interceptTest
public Object interceptTest(TestMethodInvocationContext<Object> methodInvocationContext) throws Throwable Description copied from interface:TestMethodInterceptorIntercepts each test invocation.- Specified by:
interceptTestin interfaceTestMethodInterceptor<C>- Parameters:
methodInvocationContext- the method invocation context- Returns:
- intercepted return value
- Throws:
Exception- allows any exception to propagateThrowable
-
beforeTestExecution
Description copied from interface:TestExecutionListenerExecuted before a single test iteration is executed.- Specified by:
beforeTestExecutionin interfaceTestExecutionListener- Parameters:
testContext- the test context- Throws:
Exception- allows any exception to propagate
-
beforeCleanupTest
Description copied from interface:TestExecutionListenerExecuted before the setup method of a test method.- Specified by:
beforeCleanupTestin interfaceTestExecutionListener- Parameters:
testContext- the test context- Throws:
Exception- allows any exception to propagate
-
afterCleanupTest
Description copied from interface:TestExecutionListenerExecuted after the setup method of a test method.- Specified by:
afterCleanupTestin interfaceTestExecutionListener- Parameters:
testContext- the test context- Throws:
Exception- allows any exception to propagate
-
afterTestExecution
Description copied from interface:TestExecutionListenerExecuted after a single test iteration has been executed .- Specified by:
afterTestExecutionin interfaceTestExecutionListener- Parameters:
testContext- the test context- Throws:
Exception- allows any exception to propagate
-
beforeTestClass
Description copied from interface:TestExecutionListenerExecuted before all of the tests of a class are executed.- Specified by:
beforeTestClassin interfaceTestExecutionListener- Parameters:
testContext- the test context- Throws:
Exception- allows any exception to propagate
-
afterTestClass
Description copied from interface:TestExecutionListenerExecuted after all of the tests of a class have bean executed.- Specified by:
afterTestClassin interfaceTestExecutionListener- Parameters:
testContext- the test context- Throws:
Exception- allows any exception to propagate
-
beforeSetupTest
Description copied from interface:TestExecutionListenerExecuted before the setup method of a test method.- Specified by:
beforeSetupTestin interfaceTestExecutionListener- Parameters:
testContext- the test context- Throws:
Exception- allows any exception to propagate
-
afterSetupTest
Description copied from interface:TestExecutionListenerExecuted after the setup method of a test method.- Specified by:
afterSetupTestin interfaceTestExecutionListener- Parameters:
testContext- the test context- Throws:
Exception- allows any exception to propagate
-
beforeTestMethod
Description copied from interface:TestExecutionListenerExecuted before a test method is executed (a test method may contain multiple iterations).- Specified by:
beforeTestMethodin interfaceTestExecutionListener- Parameters:
testContext- the test context- Throws:
Exception- allows any exception to propagate
-
afterTestMethod
Description copied from interface:TestExecutionListenerExecuted after a test method has been executed (a test method may contain multiple iterations).- Specified by:
afterTestMethodin interfaceTestExecutionListener- Parameters:
testContext- the test context- Throws:
Exception- allows any exception to propagate
-
beforeClass
protected void beforeClass(C context, Class<?> testClass, @Nullable @Nullable MicronautTestValue testAnnotationValue) Executed before tests within a class are run.- Parameters:
context- The test contexttestClass- The test classtestAnnotationValue- The test annotation values
-
postProcessBuilder
protected void postProcessBuilder(io.micronaut.context.ApplicationContextBuilder builder) Allows subclasses to customize the builder right before context initialization.- Parameters:
builder- the application context builder
-
resolveTestProperties
protected abstract void resolveTestProperties(C context, MicronautTestValue testAnnotationValue, Map<String, Object> testProperties) Resolves any test properties.- Parameters:
context- The test contexttestAnnotationValue- The test annotationtestProperties- The test properties
-
beforeEach
protected void beforeEach(C context, @Nullable @Nullable Object testInstance, @Nullable @Nullable AnnotatedElement method, List<io.micronaut.context.annotation.Property> propertyAnnotations) To be called by the different implementations before each test method.- Parameters:
context- The test contexttestInstance- The test instancemethod- The test methodpropertyAnnotations- The@Propertyannotations found in the test method, if any
-
afterClass
Executed after the class is complete.- Parameters:
context- the context
-
afterEach
Executed after each test completes.- Parameters:
context- The context- Throws:
Exception- allows any exception to propagate
-
startApplicationContext
protected void startApplicationContext()Starts the application context. -
isTestSuiteBeanPresent
- Parameters:
requiredTestClass- The test class- Returns:
- true if the te given class has a bean definition class in the classpath (ie: the annotation processor has been run correctly)
-
alignMocks
- Parameters:
context- The contextinstance- The mock instance to inject
-