Interface AxonTestPhase


public interface AxonTestPhase
Interface describing the operations available on a test phase for testing Axon-based applications using a given-when-then pattern. The test phase provides a fluent API to configure and execute tests against Axon components.

This interface defines four primary phases of a test:

The test fixture manages UnitOfWork instances during test execution, automatically committing as appropriate. During the Given phase, each operation (like AxonTestPhase.Given.event(java.lang.Object)}, AxonTestPhase.Given.command(java.lang.Object) or even batched like AxonTestPhase.Given.events(org.axonframework.messaging.eventhandling.EventMessage...) and AxonTestPhase.Given.commands(org.axonframework.messaging.commandhandling.CommandMessage...)) is executed in its own separate UnitOfWork that is committed immediately after execution. In the When phase, a single Unit of Work is started and committed after the command is executed. The Then phase only validates the results.

The test phases operates on components defined in Configuration that you pass to the fixture during its construction.

Typical usage example:

 
 var fixture = AxonTestFixture.with(configurer);

 fixture.given()
        .event(new AccountCreatedEvent("account-1"))
        .when()
        .command(new WithdrawMoneyCommand("account-1", 100.00))
        .then()
        .success()
        .events(new MoneyWithdrawnEvent("account-1", 100.00));
 
 

Example with chaining multiple test scenarios using and():

 
 var fixture = AxonTestFixture.with(configurer);

 fixture.given()
        .event(new AccountCreatedEvent("account-1", 500.00))
        .when()
        .command(new WithdrawMoneyCommand("account-1", 100.00))
        .then()
        .events(new MoneyWithdrawnEvent("account-1", 100.00))
        .success()
        .and()
        .when()
        .command(new WithdrawMoneyCommand("account-1", 500.00))
        .then()
        .exception(InsufficientBalanceException.class)
        .noEvents();
 
 
Since:
5.0.0
Author:
Allard Buijze, Mateusz Nowak, Mitchell Herrijgers, Steven van Beelen
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Interface describing the operations available in the Given phase of the test fixture execution.
    static interface 
    Interface describing the initial setup phase of a test fixture.
    static interface 
    Interface describing the operations available in the Then phase of the test fixture execution.
    static interface 
    Interface describing the operations available in the When phase of the test fixture execution.