How to Write Acceptance Tests for Event-Driven Applications Built With Axon?

Hello everyone,

I’d like to get the community’s thoughts on best practices for testing the behavior of an application built with Axon, specifically around acceptance testing for event-driven applications.

Here’s the idea:

In the acceptance tests, we run the application, required DBs, and the event store in Docker containers, and we use MockServer to mock the external systems we depend on.

I’m considering the following approach:

  1. At the end of the test scenario, fetch the list of events from the event store and assert that the expected events were published.
  2. On the unit test level, use Axon’s testing libraries to verify that when a given event is published, the correct action is taken

My questions are:

  1. Do you think this is a good approach to validate the behavior of an application built with Axon?
  2. Is there a better or recommended way to write acceptance tests for an application built with Axon?
  3. In particular, should acceptance tests focus on asserting state changes and verifying that an external system was called correctly, instead of or in addition to verifying the events?

I’d appreciate any insights or examples from your own projects.

Thank you,
Alain

Hi Alain!

To be honest, for acceptence tests, I would not test the deployed application.

For accepence tests, I would use e.g. Cucumber and the axon framework for tests.
Using this, you can easily and very fast test the use cases.

But furthermore some integrationtests are necessary, where you verify that finally events are stored somewhere. But there should be just a handful test for that.

I have the experience that test for deployed system are quite to slow and too expensive to test every use case.

Best regards

Markus

1 Like

Hello Markus,

Thank you for your reply! I agree with you that testing the deployed application is slow. I’m interested in your idea about using Cucumber with Axon’s testing tools.

Could you tell me more about how do you set up these Cucumber tests with Axon? Can you share a simple example of what these tests look like? Do you use an in-memory event store, or do you only use the testing fixtures provided by Axon e.g AggregateTestFixture and SagaTestFixture?

Best,
Alain