the fixture isn’t really meant to run in a Spring context. Instead, the Fixture sets up special implementations of messaging components that are capable of validating your expectations. The fixture will already set up an Event Sourcing Repository, for example.
Hi ,
My test cases are being passed, but no data is being saved when I run the test cases. Event handlers are not being automatically called with axon tests. Am I missing something in fixture configuration? What is the correct way to set/ register repository in fixture, if I am using MongoDB as event sourcing repository. Can you please send me an example which demonstrates this? Any help regarding this will be much appreciated.
The test fixtures are for unittests, so you can test whether a command results in the expected events etc. It is not meant for an integration test where you might want to have actual persistence to a database. Also, the CommandBus and EventBus in the fixtures are testbusses, so no complete application flow will be performed.
If you do want to run an integrationtest I suggest to use a testcalls annotated with:
Thank you so much Frank for bring the clarity. Let me give you quick background of my code. I have seperate classes for each command handler ( except for create customer, which is defined in CustomerAggregate class.) . In the handle() , I have to load the aggregate first EventSourcingRepository.load(), and then use apply ()( which is defined in Aggregate class). My test cases are passing for addCustomer(), since the handler for the same is defined for aggregate itself. But for other update commands, test cases are failing, because when the flow of execution reaches the handler() for any update command, it gets NullPointerException, for EventSourcingRepository, when it tries to load the aggregate for that aggregate identifier. I am using MongoDB as event source repository. Can you please guide me which this concept, and what I need to change in fixture configuration for the same.
I think you’re still combining two different concepts, here. The test fixtures merely simulate infrastructure for testing purposes. So you don’t actually use mongo in them. My guess of what’s happening is, is that you are not reading from the correct repository instance. The Fixture create a repository that you should use for the tests. This repository is the one you need to inject in your Command Handler.