TypeMock IsolatorMocks/Fakes/StubsBy Brandon D’ImperioImaginaryDevelopment@gmail.com
Testing is hard!• Testing is too much work• I can’t get my developers to write tests• I can’t get my teammates to write te...
Jargon/Definitions• Unit Test– Code (usually a method) that runs another piece of code (usually a single method/function i...
Testing Types
Testing• User Model Testing - link• Acceptance Testing - link• Usability Testing• Performance and load testing• Security T...
Unit Testing weaknesses• Can not catch integration errors, system-levelerrors, or non-functional (performance,security, et...
Unit Testing strengths• A code driven documentation– Less likely to get out of sync than comments– Less likely to get out ...
What is a good unit test?• Automated/repeatable• Easy to implement• Once written, remains for future use/versions• Anyone ...
What’s a mock/isolation framework?• In order to properly unit test your externaldependencies must be replaced. A unit test...
What does TypeMock bring?• Fake static/sealed/non-public elements– DateTime.Now faking!• No design for testability require...
Code!• Let’s look at some actual code
TypeMock vs Others• Some mock frameworks can only mockinterfaces• nUnit.Mocks – no events or generics mocking• Rhino Mocks...
Debate• Advocates of Testability say you don’t get theclean SOLID design of writing for testability• Should the isolation ...
TDD and indirectly unit testingresearch• "We found that test-first students on average wrote more tests and,in turn, stude...
More reading…• Martin Fowler – Mocks aren’t stubs• Uncle Bob – TDD Derangement Syndrome
Good Practices• Only a single Assert per test• Code a test for both the Happy Path and theUnhappy Path• Start out testing ...
My Passions• Tooling anything that makes coding easier ormore productive• MVC• Extensibility
Upcoming SlideShare
Loading in …5
×

Type mock isolator

517 views

Published on

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
517
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Reference: http://weblogs.asp.net/rosherove/archive/2007/04/26/choosing-a-mock-object-framework.aspxNmock: http://www.nmock.org/cheatsheet.html
  • Type mock isolator

    1. 1. TypeMock IsolatorMocks/Fakes/StubsBy Brandon D’ImperioImaginaryDevelopment@gmail.com
    2. 2. Testing is hard!• Testing is too much work• I can’t get my developers to write tests• I can’t get my teammates to write tests• My codebase was not written with testability• Mocking frameworks take too much work tofake out deep call chains• My dependencies are static, sealed, or non-public and can’t be faked
    3. 3. Jargon/Definitions• Unit Test– Code (usually a method) that runs another piece of code (usually a single method/function inisolation) and checks the correctness of an assumption afterward. If the assumptions arewrong, the unit test is failed.• Fake– Encapsulates noth Stubs and Mocks• Stub– A controllable replacement for an existing dependency in the system.– Use a stub to test your code without dealing with the dependency directly– Can not fail a test– Usually just a dummy object that does nothing, returns property values as instructed– Not the item being tested again• Mock– A fake object in the system that decides whether the unit test has passed or failed.– Does so by verifying whether the object under test interacted as expected with the Fake
    4. 4. Testing Types
    5. 5. Testing• User Model Testing - link• Acceptance Testing - link• Usability Testing• Performance and load testing• Security Testing• Integration Testing• Unit Testing – uses fakes to isolate
    6. 6. Unit Testing weaknesses• Can not catch integration errors, system-levelerrors, or non-functional (performance,security, etc)• Additional maintenance• Additional coding• Unit tests may share the same blind spots asthe code because they are written by thesame developer
    7. 7. Unit Testing strengths• A code driven documentation– Less likely to get out of sync than comments– Less likely to get out of sync than documentation• Regression reduction• Instant feedback• Safer refactoring and feature addition• Unit tests may help the developer find blindspots
    8. 8. What is a good unit test?• Automated/repeatable• Easy to implement• Once written, remains for future use/versions• Anyone should be able to run it• Runs quickly (up to 20,000 in a minute)– No dependencies
    9. 9. What’s a mock/isolation framework?• In order to properly unit test your externaldependencies must be replaced. A unit testshould ONLY fail because of the code you aretesting, otherwise it’s an integration test.• A mock framework is a tool to replace externaldependencies with fakes.
    10. 10. What does TypeMock bring?• Fake static/sealed/non-public elements– DateTime.Now faking!• No design for testability required• Recursive fakes (nested call chains) a.b.c.d
    11. 11. Code!• Let’s look at some actual code
    12. 12. TypeMock vs Others• Some mock frameworks can only mockinterfaces• nUnit.Mocks – no events or generics mocking• Rhino Mocks – no strings for method names,single developer (if he stops, game over?)– Documentation does not appear to support non-interface mocking• nMock 2.0 – currently in RC status, appears torequire interfaces to fake
    13. 13. Debate• Advocates of Testability say you don’t get theclean SOLID design of writing for testability• Should the isolation framework be dictatingdesign decisions?• Design for testability leaves out the majorityof work… Brownfield applications
    14. 14. TDD and indirectly unit testingresearch• "We found that test-first students on average wrote more tests and,in turn, students who wrote more tests tended to be moreproductive. We also observed that the minimum quality increasedlinearly with the number of programmer tests, independent of thedevelopment strategy employed."• "The external validity of the results could be limited since thesubjects were students. Runeson [21] compared freshmen,graduate, and professional developers and concluded that similarimprovement trends persisted among the three groups. Replicatedexperiments by Porterand Votta [22] and Höst et al. [23] suggest that students mayprovide an adequate model of the professional population."• Taken fromhttp://weblogs.asp.net/rosherove/archive/2008/01/25/research-finds-tdd-boosts-developer-productivity.aspx
    15. 15. More reading…• Martin Fowler – Mocks aren’t stubs• Uncle Bob – TDD Derangement Syndrome
    16. 16. Good Practices• Only a single Assert per test• Code a test for both the Happy Path and theUnhappy Path• Start out testing by hitting your longest, mostcyclomatically complex, most critical, or justhardest to understand methods.• Try to reduce the external dependency contactpoints in a class• Write a test that FAILS first! Write the test beforethe code, or comment out the part that shouldmake it succeed.
    17. 17. My Passions• Tooling anything that makes coding easier ormore productive• MVC• Extensibility

    ×