Daniel Wellman
2015-10-22 23:25:06 UTC
Hi all,
I've been thinking about using mock objects and the advice of "Expect commands, stub queries" and had a question for the group.
When I explain why I follow this rule it's because:
I want the test to communicate the difference between commands and queries to future readers so they understand which parts are essential. That is, commands are usually the most important part, and queries are a way to provide information to the code under test.
... But the object could be free to obtain that information in any way it wants. If the production code changed to get that query information from another collaborator, or manufactured the data itself, the test should not fail on an unused query ("allowing()") test double setup.
If this scenario happened though, it probably would mean that an abandoned "allowing()" clause could still exist in the test, leaving clutter and noise for the next reader. You need to remember to delete that unused allowing clause to keep the code clean.
So if you want to keep your tests clean of unused test double setup, you'll need to change (delete) that line of code from your test when the production code changes.
... So then I'm left with "Expect commands and stub queries is primarily a communication tool to the test reader."
What am I missing, if anything?
How do other folks on this list explain this distinction?
Thanks!
Cheers
Dan
I've been thinking about using mock objects and the advice of "Expect commands, stub queries" and had a question for the group.
When I explain why I follow this rule it's because:
I want the test to communicate the difference between commands and queries to future readers so they understand which parts are essential. That is, commands are usually the most important part, and queries are a way to provide information to the code under test.
... But the object could be free to obtain that information in any way it wants. If the production code changed to get that query information from another collaborator, or manufactured the data itself, the test should not fail on an unused query ("allowing()") test double setup.
If this scenario happened though, it probably would mean that an abandoned "allowing()" clause could still exist in the test, leaving clutter and noise for the next reader. You need to remember to delete that unused allowing clause to keep the code clean.
So if you want to keep your tests clean of unused test double setup, you'll need to change (delete) that line of code from your test when the production code changes.
... So then I'm left with "Expect commands and stub queries is primarily a communication tool to the test reader."
What am I missing, if anything?
How do other folks on this list explain this distinction?
Thanks!
Cheers
Dan
--
---
You received this message because you are subscribed to the Google Groups "Growing Object-Oriented Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to growing-object-oriented-software+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
---
You received this message because you are subscribed to the Google Groups "Growing Object-Oriented Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to growing-object-oriented-software+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.