AggregateVerifier
Aggregate Verifier provides utilities for testing domain aggregates using the Given/When/Expect pattern.
This object facilitates setting up and executing tests for aggregate behavior by providing methods to create GivenStage instances. The Given/When/Expect pattern allows for declarative testing of command handling, event production, and state changes in domain aggregates.
Key features:
Fluent API for test setup and verification
Support for event sourcing and state-based aggregates
Integration with in-memory event stores for isolated testing
Dependency injection support via ServiceProvider
Multi-tenant aggregate testing capabilities
Example usage:
aggregateVerifier<Cart, CartState>()
.given(CartItemAdded(...))
.whenCommand(AddCartItem(...))
.expectEventType(CartItemAdded::class)
.expectState { items.assert().hasSize(1) }
.verify()Author
ahoo wang
Functions
Creates a GivenStage for testing an aggregate using the command class as the aggregate type.
Creates a GivenStage for testing an aggregate with explicit command and state types.