Exploring the Future Potential of AI-Enabled Smartphone Processors
.NET Unit Testing w/ Microsoft Fakes (TechCamp Memphis Spring 2012)
1. .NET Unit Testing
http://wp.me/pjaaL-1o
with
Microsoft Fakes (Beta)
@lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance
3. Why should I be unit testing?
• You have:
• No idea what you’re doing to your code
• No idea what they’re doing to your code
• No idea what’s going to change in the future
• You need:
• To protect your code from you
• To protect your code from them
• To protect today’s work from tomorrow’s changes
@lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance
4. A “unit” is what you isolate.
• Your method has dependencies:
• The logging thing (the analytics thing?)
• The database thing (the web service thing?)
• The thing that gets input from the UI
• You need:
• To test your unit’s logic, not dependencies
• To control your dependencies
• To test all logic anytime the code changes
@lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance
5. Keep the “unit”. Lose the rest.
• “Faking” – also known as:
• Stubbing – test classes instead of dependencies
• Mocking – frameworks instead of dependencies
• Isolating – what’s my “unit”? Key question!
• You need:
• To remove the unknowns of dependencies
• To test the “unit” in different scenarios
• To design your code independent of testing tools
@lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance
6. How do I use Microsoft Fakes?
• Stubs (similar to Moq, Rhino Mocks, etc.)
• faking “well-designed” dependencies (recommended)
• Shims (similar to Isolator, Just Mock Pro, etc.)
• faking “poorly-designed” dependencies (powerful)
• performance overhead; runtime code rewriting
• Verify
• the “unit” used dependencies as expected
• no verify support (yet?)
@lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance
7. Onto the Code!
@lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance
8. Thank You for letting me share.
• Say Hello!
• Blog: http://notworthrepeating.blogspot.com (slides/code)
• Google+: http://gplus.to/lance Twitter: @lancehilliard
• Email: lance@digitalcreations.cc
• Relevant Reading
• Isolating Unit Test Methods with Microsoft Fakes (MSDN)
http://tinyurl.com/msfakes
• Using stubs to isolate calls to virtual functions
• Using shims to isolate calls to non-virtual functions
• Code generation, compilation, and naming conventions
• Recommended Reading
• The Clean Coder: A Code of Conduct for Professional Programmers
http://tinyurl.com/thecleancoder
@lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance