0

I got multiple value objects (VOs) inside my aggregate root (AR).

Each VO does invariant checks when created, such as string min/max length, regexp, etc.

Each VO is created when the AR is created and the AR is unit tested with 100% coverage.

Since the AR is created inside an application service, and AR and its VOs can't be mocked, am I supposed to test all of the possible invariants all over again when testing the application service? It feels like I would be writing tests that would be very similar to the ones I've already written for the AR, but at the same time if I do not repeat those tests for the application service I have no guarantees that the invariants would be verified.

Andrea Damiani
  • 611
  • 1
  • 6
  • 20

1 Answers1

0

I think you answered your own question. If you need a guarantee that the Invariants will be verified then you must write the tests. There are other reasons why the answer should be "Yes" but I don't think there's any reason as good as that one.

Separate from my answer above: I can't say for sure without more information, but generally speaking: when you have a setup like you desribed, all tests in the AR that "touch" your Invariant will do so incidentally and not specifically. Your tests must also be able to serve as documentation for your code to take maintainability to the next level. To this end, you should write tests that specifically exercise the invariants.

Louis
  • 1,194
  • 1
  • 10
  • 15