re: I use test-driven development every day, ask me anything VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Do you write tests for value objects in strongly typed languages, and if so why?
 

Hey Neil,

I know that it is a typical consulting answer, but it depends. If there is logic in the methods on a value object, I would definitely write tests. However if functions simply return a static value, I would leave those untested. I usually try to test how groups of objects and functions interact together. With that style I am free to extract out data structures or value objects that don't have their own tests, but are tested through a higher order interaction.

The factors at play are 1) how confident am I that the value object is a stable abstraction 2) is the behavior something that could actually break.

If I am confident that it can't break, I don't write a test.

If it is an unstable abstraction, I test it through an abstraction that is stable.

Thanks for your question!

code of conduct - report abuse