There have been some concerns on the web about TypeMock being too easy, and thus dangerous.
I am really flattered with that distinction. TypeMock does make your life easy.
Here are a few tips to keep you mocking safely.
- Test Features and not classes.
Test features, even if they span on a few classes. Remember that you may refactor the code anyway into several classes. Once you know what features you are implementing testing, it will be easier to know what to mock. - Build a Mocked-Framework.
Create a framework with your mocks, this will help when refactoring your code.
It will also make your tests clearer[Test] public void SomeTest() { MyMockUtils.StubLogging(); MyMockUtils.FakeCusomters(); // continue with test } - Use Stubs more often
Stubs and Conditional Expectations should be used more often - Refactor Your Code
There is no excuse not to do this. Always think about how your production code is structured and refactor it.Don’t change you design just to test. There is no reason to start making private methods public and delivering code that are just for testing - Refactor Your Tests
Make sure your mocks say everything once and push tests into your Mocked Framework.