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 MessagesRecordingConfigurationEnhancer so that commands and events are recorded during the test.
  • Expose an AxonTestFixture bean 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 Elements
    Modifier and Type
    Optional Element
    Description
    Application arguments that should be passed to the application under test.
    Class<?>[]
    The component classes to use for loading an ApplicationContext.
    Properties in form key=value that should be added to the Spring Environment before the test runs.
    org.springframework.boot.test.context.SpringBootTest.UseMainMethod
    The type of main method usage to employ when creating the SpringApplication under test.
    Alias for SpringBootTest.properties().
    org.springframework.boot.test.context.SpringBootTest.WebEnvironment
    The type of web environment to create when applicable.
  • Element Details

    • value

      @AliasFor(annotation=org.springframework.boot.test.context.SpringBootTest.class, attribute="value") String[] value
      Alias for SpringBootTest.properties().
      Returns:
      the properties to apply
      See Also:
      • SpringBootTest.value()
      Default:
      {}
    • properties

      @AliasFor(annotation=org.springframework.boot.test.context.SpringBootTest.class, attribute="properties") String[] properties
      Properties in form key=value that should be added to the Spring Environment before the test runs.
      Returns:
      the properties to add
      See Also:
      • SpringBootTest.properties()
      Default:
      {}
    • args

      @AliasFor(annotation=org.springframework.boot.test.context.SpringBootTest.class, attribute="args") String[] args
      Application arguments that should be passed to the application under test.
      Returns:
      the application arguments to pass to the application under test
      See Also:
      • SpringBootTest.args()
      Default:
      {}
    • classes

      @AliasFor(annotation=org.springframework.boot.test.context.SpringBootTest.class, attribute="classes") Class<?>[] classes
      The component classes to use for loading an ApplicationContext. If no explicit classes are defined, the test will look for nested @Configuration classes before falling back to a @SpringBootConfiguration search.
      Returns:
      the component classes used to load the application context
      See Also:
      • SpringBootTest.classes()
      Default:
      {}
    • webEnvironment

      @AliasFor(annotation=org.springframework.boot.test.context.SpringBootTest.class, attribute="webEnvironment") org.springframework.boot.test.context.SpringBootTest.WebEnvironment webEnvironment
      The type of web environment to create when applicable. Defaults to SpringBootTest.WebEnvironment.MOCK.
      Returns:
      the type of web environment
      See Also:
      • SpringBootTest.webEnvironment()
      Default:
      MOCK
    • useMainMethod

      @AliasFor(annotation=org.springframework.boot.test.context.SpringBootTest.class, attribute="useMainMethod") org.springframework.boot.test.context.SpringBootTest.UseMainMethod useMainMethod
      The type of main method usage to employ when creating the SpringApplication under test. Defaults to SpringBootTest.UseMainMethod.NEVER.
      Returns:
      the type of main method usage
      See Also:
      • SpringBootTest.useMainMethod()
      Default:
      NEVER