unit test failing with the Axon Server

I have a problem running a test in my test app when using the Axon Server.

The project is at:


The test is very simple : create a credit card and make purchases.


Other simpler tests without prior activity are green.

For instance:

public void test_create_credit_card_with_100_limit() {
            .when(new IssueCmd("123", "me", 100))
            .expectEvents(new IssuedEvt("123", "me", 100));

The failing tests are the tests with the given non null:

public void test_purchase_with_credit_card_with_100_limit() {
    final PurchaseCmd purchase = new PurchaseCmd("123", 10);
            .given(new IssueCmd("123", "me", 100))
            .expectEvents(new PurchasedEvt("123", 10));

And then I get the (sadly) usual error :

org.axonframework.test.AxonAssertionError: The published events do not match the expected events

Expected Actual
com.sapient.demo.creditcard.api.PurchasedEvt < >

A probable cause for the wrong chain of events is an exception that occurred while handling the command.
org.axonframework.eventsourcing.IncompatibleAggregateException: Aggregate identifier must be non-null after applying an event. Make sure the aggregate identifier is initialized at the latest when handling the creation event.

The starting point for the demo is your giftcard demo taken off your github account.

That project does not present any unit test so I could not get any working example.


Hi Antonio,

note that the test fixtures don’t use AxonServer. They simulate infrastructure for the purpose of testing.
In your tests, you specify
.given(new IssueCmd(“123”, “me”, 100))

However, that’s a command, not an event.
If you were to do:
.given(new IssuedEvt(“123”, “me”, 100))

it works.
Alternatively, use .givenCommands(…)



It worked.

Lovely. Thanks.