How to unit test Aggregate Snapshots

Goal: Store an XML file of the existing structure of an aggregate snapshot, and then use that XML in a unit test. The goal here would be to assert that any changes to a snapshotted aggregate are backwards compatible and do not produce unexpected errors when deploying to existing environment. Would be nice to detect these issues at build-time.

Attempts: I’ve tried to use the .givenState() method, but that does not appear to work for event-sourced aggregates. I get the following error message

No ‘given’ events were configured for this aggregate, nor have any events been stored.

Is this possible?

Hi Kramer,

I think the easiest solution to testing Aggregate Snapshots, is to run an Aggregate’s XML (or JSON, depending on the serialized format) through the Serializer you have configured.
In the end, that is what the framework uses to deserielize a snapshot to an actual Aggregate instance too.
Thus, in your sample you would have a test that contains the serialized XML format of said Aggregate, which you would deserialize with the XStreamSerializer you have set up in your application.

By any means, the Test Fixtures are not intended to test (de-)serialization of Aggregate instances.
They only service given-when-then test scenarios for the actual business logic contained in your aggregate.

Cheers,
Steven