Sign in to track progress and bookmarks.
Because your Domain layer has zero dependencies, it is the easiest and fastest part of your application to test.
You don't need mocks to test a Domain Entity. You just instantiate the class and call its methods. var user = new User(); user.Deactivate(); Assert.False(user.IsActive);. These tests run in milliseconds. You can run 1,000 of them in seconds, giving you near-instant feedback on your business rules.
Focus on 'Behavior' rather than 'State'. Test that an entity raises the correct **Domain Event** when a certain condition is met. This ensures that the 'intent' of your domain logic is captured and preserved as the code evolves.
Q: "Should I test my private fields?"
Architect Answer: "NO. Test the public API of your domain. If a business rule requires that a Discount can't be negative, test that passing a negative value to the ApplyDiscount() method throws an error (or returns a failure result). Testing internals makes your tests brittle. Testing behavior makes your architecture robust."
Quizzes linked to this course—pass to earn certificates.
On this page
1. Testing Business Rules 2. Behavioral Testing 3. Architect Insight