'Unit Testing - How to build tests around domain entities with lots of encapsulation and many internal states
Admittedly, very new to Unit Testing right now but I'm wanting to make sure I don't end up with a testing project that ends up being a nightmare to maintain.
The big challenge for me right now is how to test behaviors of an entity when it requires the object to be in a certain state, which is achieved through any number of prior method calls. There are no public setters to properties. I am messing around with SpecimenBuilders in AutoFixture, and have a "default state" object builder that creates the entity using its public constructor, but then I get stuck.
Ideally, I'd like to build off this concept and have other builders that create that same entity type but in other states beyond the default, using the SpecimenBuilder that creates the entity in the default state without having to repeat code, and then calling the method to get the entity to next state. Or maybe I'm off track completely here on what I'm thinking. Perhaps I need to just create custom Object Mothers for all this.
I'm open to any suggestions on the best way to approach things. Thanks so much.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|