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.
- 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.
Recent Posts
- Product Status Peek – 2011
- Thanks Roy
- Typemock starts 2011 in a new location
- Agile Demos Smells
- I want loud disputes in our meetings
Categories
- .NET Tests
- Agile
- Code Integrity
- Community
- Debugging
- Fun
- Management for Geeks
- Marketing
- Product
- Release
- Reviews
- SharePoint
- TDD
- Time Management
- Uncategorized
- Unit Tests
Archives
- January 2011
- December 2010
- October 2010
- August 2010
- May 2010
- April 2010
- March 2010
- February 2010
- December 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- December 2008
- November 2008
- August 2008
- July 2008
- May 2008
- April 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
