Mocking Safely …

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.

  1. 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.
  2. 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 }
  3. Use Stubs more often
    Stubs and Conditional Expectations should be used more often
  4. 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
  5. Refactor Your Tests
    Make sure your mocks say everything once and push tests into your Mocked Framework.

Add Comment

Required fields are marked *. Your email address will not be published.