Reputation: 1580
What is the best way to unit test a relatively complex method where the test for each post-condition is very similar to the tests for the other post-conditions? The pre-conditions are easy to test in isolation, but a lot of setup goes into making sure that they all hold so that the post-conditions can be tested. The three ways that I've thought up are:
The fourth option would be "you're doing it wrong; break the method being tested down into bits that are simpler to test!"
Any ideas?
Upvotes: 0
Views: 1014
Reputation: 41137
My earlier comment was somewhat in jest.
What I would actually advocate, broadly speaking, is to do what you list as option 2, but then refactor your test code to eliminate the duplication that you created by the copy-modify work.
Once you have this all tested, you might then look for ways to refactor the production code to break it down into smaller and more manageable pieces and make those pieces reusable. But it's always healthy to have tests before making big changes.
Upvotes: 2