We are currently using unit tests to test our project. We have the majority of functionality covered but I think our tests are too brittle.
I was wondering if there are any specific things we can be doing to make the unit tests more flexible so they don’t break for the wrong reasons.
A couple answers have mentioned being careful of mocking too much… So what are legitimate reasons for mocking? I think that may be one of our main problems, but when your application is mostly a dynamic, database-driven site, how do you get away from mocking?
This is a somewhat simplistic answer, but shows the right mindset:
So as far as is possible – without going hugely out of your way – make sure you’re testing the ‘end result’ of the method without caring how it got there. One thing to watch out for is mocking – it’s incredibly useful, but can easily make your tests brittle.