Annotation Interface AxonSpringBootTest
@Target(TYPE)
@Retention(RUNTIME)
@SpringBootTest
@Import(org.axonframework.extension.springboot.test.AxonTestConfiguration.class)
public @interface AxonSpringBootTest
Meta-annotation that combines
@SpringBootTest with the Axon test infrastructure provided by
AxonTestConfiguration.
Annotating a test class with @AxonSpringBootTest will:
- Bootstrap a full Spring Boot application context (same as
@SpringBootTest). - Register a
MessagesRecordingConfigurationEnhancerso that commands and events are recorded during the test. - Expose an
AxonTestFixturebean that can be injected directly into the test constructor or fields.
The fixture's AxonTestFixture.Customization can be overridden by declaring
a bean of that type in the test (e.g. via an inner @TestConfiguration class).
All SpringBootTest attributes (properties, classes, webEnvironment, etc.) are supported through
AliasFor.
Usage
@AxonSpringBootTest
class MySliceTest {
@Autowired
AxonTestFixture fixture;
@Test
void myTest() {
fixture.given().noPriorActivity()
.when().command(new MyCommand())
.then().events(new MyEvent());
}
}
- Since:
- 5.1.0
- Author:
- Mateusz Nowak
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionString[]Application arguments that should be passed to the application under test.Class<?>[]The component classes to use for loading anApplicationContext.String[]Properties in form key=value that should be added to the SpringEnvironmentbefore the test runs.org.springframework.boot.test.context.SpringBootTest.UseMainMethodThe type of main method usage to employ when creating theSpringApplicationunder test.String[]Alias forSpringBootTest.properties().org.springframework.boot.test.context.SpringBootTest.WebEnvironmentThe type of web environment to create when applicable.
-
Element Details
-
value
@AliasFor(annotation=org.springframework.boot.test.context.SpringBootTest.class, attribute="value") String[] valueAlias forSpringBootTest.properties().- Returns:
- the properties to apply
- See Also:
- Default:
{}
-
properties
@AliasFor(annotation=org.springframework.boot.test.context.SpringBootTest.class, attribute="properties") String[] propertiesProperties in form key=value that should be added to the SpringEnvironmentbefore the test runs.- Returns:
- the properties to add
- See Also:
- Default:
{}
-
args
@AliasFor(annotation=org.springframework.boot.test.context.SpringBootTest.class, attribute="args") String[] argsApplication arguments that should be passed to the application under test.- Returns:
- the application arguments to pass to the application under test
- See Also:
- Default:
{}
-
classes
@AliasFor(annotation=org.springframework.boot.test.context.SpringBootTest.class, attribute="classes") Class<?>[] classesThe component classes to use for loading anApplicationContext. If no explicit classes are defined, the test will look for nested@Configurationclasses before falling back to a@SpringBootConfigurationsearch.- Returns:
- the component classes used to load the application context
- See Also:
- Default:
{}
-
webEnvironment
@AliasFor(annotation=org.springframework.boot.test.context.SpringBootTest.class, attribute="webEnvironment") org.springframework.boot.test.context.SpringBootTest.WebEnvironment webEnvironmentThe type of web environment to create when applicable. Defaults toSpringBootTest.WebEnvironment.MOCK.- Returns:
- the type of web environment
- See Also:
- Default:
MOCK
-
useMainMethod
@AliasFor(annotation=org.springframework.boot.test.context.SpringBootTest.class, attribute="useMainMethod") org.springframework.boot.test.context.SpringBootTest.UseMainMethod useMainMethodThe type of main method usage to employ when creating theSpringApplicationunder test. Defaults toSpringBootTest.UseMainMethod.NEVER.- Returns:
- the type of main method usage
- See Also:
- Default:
NEVER
-