Beyond Unit Testing => Specification of Intent

Beyond Unit Testing => Specification of Intent

09 Jun, 2010

It seems like every day my unit testing style becomes more and more stylized and it seems I am driving toward something specific, elegant and readable. I want my tests to not only validate that the code does what I think it should do, but it also tells the story of what is happening and how. The latest permutation of this obsession has me focusing on the context of my specifications. Why have lines and lines of object initialization code when I can instead explicitly state the context that the tests are running under in an expressive way?

Consider the two following code samples. Does either help you to understand the intent of the system under test? Which do you prefer? Why? Do you find it silly? Pointless?