2

An aggregate can represent a somewhat stable system boundary.

Does it make sense to write input and output test aggregates to do most testing? In theory we could use an aggregate as a data driven way to do testing. We can create data that is going into our system without a database layer and we get a processed aggregate out. We could potentially specify a lot of cases this way.

The risk here is that we are limiting our ability to modify the aggregates because we may need to rewrite all our test aggregates if an aggregate changes. Although we could migrate them.

  • 4
    "we may need to rewrite all our test aggregates if an aggregate changes." If your aggregates change, it usually means that your understanding of the domain has changed -- your tests are likely to need attention under those circumstances anyway.... – VoiceOfUnreason Mar 5 '16 at 1:51
3

Aggregates are definitely good candidates for unit testing because

  • They contain part of the domain logic of your application. There's intelligence in them (invariant checking, state transitions, calculations, event firing, etc.) that you want to be correct.

  • Aggregates are supposed to be devoid of I/O related stuff. You can compose an Aggregate in memory, call one of its methods to test it and everything will be fast and isolated from the other layers.

Functional changes are IMO not a valid argument against unit testing aggregates - or against any kind of tests for that matter. Tests are executable specification. If the requirements changes, some tests have to change.

5

When you are going to unit test a class or method which takes an aggregate as input and/or output, think about what the alternative would mean.

You obviously need a way to provide test data to the "subject under test". Either use the existing, public interface, reusing your aggregates for the test data, or you can create an artifical interface just for testing purposes, which duplicates the whole data of your aggregates in a different way. I would not expect this to cause less maintenance effort than the effort you get from an aggregate change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.