Recently I’ve been following Roy’s ISerializable blog’s series on test-case reviews:
Test Review #1 – NerdDinner
Test Review #2 – ASP.NET MVC
Test Review #3 – Unity
They have been fairly informative and full of insight into Roy’s view of proper testing. One thing he keeps commenting on continues to strike a nerve of mine. Roy clearly believes that a single assert per test is THE way to go. My problem is I still fail to see his reasoning here. He has stated in all three videos that this is a bad idea since all the asserts after the first failure will not execute. OK, this is true; however, isn’t the goal to make it all pass and if so why does it matter? Even if the arrange/act of the test is only 1 or 2 lines, I would be livid with a developer that copy/pasted those lines into 20+ functions just so he could have a single assert per test. Doesn’t that make it unmaintainable? Doesn’t spreading this across 20+ methods make it hard to read?
What are your thoughts? Do you write a single assert per test? How much duplication of code do you then suffer?