1

How to start with TDD in Domain layer, and what I mean by this is how to test Domain Models?

What is it that should be tested? the Aggregates or each Entity ?

What are some good practices and strategies for testing the onion architecture Domain layer ?

1 Answers1

1

Here is a very good example of Vaughn Vernon on how to test the Domain Model:

https://github.com/VaughnVernon/IDDD_Samples/tree/master/iddd_collaboration/src/test/java/com/saasovation/collaboration

Check the subpackage, each packages test a layer of the onion architecture:

  • the application layer,
  • the domain layer,
  • the infrastructure layer

On the domain model tests, each components are tested: aggregates for their methods, entities and even value objects.

He is the author of the book Implementing Domain Driven Design, and he writes examples in java and C#. He is recognized for his work in the DDD community and his work promotes good practices. I suggest you to also read his book to learn more about this fascinating subject.

Sylvain Lecoy
  • 947
  • 6
  • 15
  • 1
    The application layer also uses the domain layer. Do application tests then indirectly also test the domain? According to Martin Fowler we should avoid test duplication, e.g. "If you have tested all conditions confidently on a lower-level test, there's no need to keep a higher-level test in your test suite." – IceFire Jun 10 '22 at 08:39
  • @IceFire that's a good point. If you check the application tests does indirectly test the domain BUT not the SPI. Repositories are mocked/in memory. The application test boots the application config, with port adapters (API) and the domain tests boots the domain config, with only port adapters (SPI) required: e.g. database connection/schema validation. – Sylvain Lecoy Oct 20 '22 at 16:12