I often find that the tests I write can be slowly generalized as the feature I happen to be working on is fleshed out. In
xUnit.net terms I find that a fair number of the tests tend to move through these four stages:
- Start out as a single [Fact], working on hardcoded input data
- Pull out the hardcoded data, turning the tests into a [Theory, AutoData]
- Add edge cases, evolving the test into [Theory, AutoData, InlineData, InlineData]
- Add cases representative of equivalence classes, thus adding more InlineData attributes to the test
Each of the stages generalizes the test a bit more making it more potent in several ways. As the test moves through each stage it gains greater coverage in terms of the possible inputs, making it a better regression guard. But there is more at play. Along with the generalization (and multiplication) of the inputs the test can often be refactored towards being more about the behavior of the
SUT and less about its implementation. So alongside the four stages above I find tests tend to move through these stages as well:
- While being a [Fact] the test is named something very specific - a specific example of how the SUT should behave
- During stage 2 or 3 the test name becomes something that expresses a general trait of the SUT
- The assertions in the test becomes less dependent on implemntation details
I am not always able to make my tests follow either of these progressions, but when I am I find it very rewarding.
No comments:
Post a Comment