SlideShare ist ein Scribd-Unternehmen logo
1 von 17
TypeMock Isolator

       Mocks/Fakes/Stubs
      By Brandon D’Imperio
ImaginaryDevelopment@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 tests
• My codebase was not written with testability
• Mocking frameworks take too much work to
  fake out deep call chains
• My dependencies are static, sealed, or non-
  public and can’t be faked
Jargon/Definitions
•   Unit Test
     – Code (usually a method) that runs another piece of code (usually a single method/function in
       isolation) and checks the correctness of an assumption afterward. If the assumptions are
       wrong, 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
Testing Types
Testing
•   User Model Testing - link
•   Acceptance Testing - link
•   Usability Testing
•   Performance and load testing
•   Security Testing
•   Integration Testing
•   Unit Testing – uses fakes to isolate
Unit Testing weaknesses
• Can not catch integration errors, system-level
  errors, or non-functional
  (performance, security, etc)
• Additional maintenance
• Additional coding
• Unit tests may share the same blind spots as
  the code because they are written by the
  same developer
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 blind
    spots
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
What’s a mock/isolation framework?
• In order to properly unit test your external
  dependencies must be replaced. A unit test
  should ONLY fail because of the code you are
  testing, otherwise it’s an integration test.
• A mock framework is a tool to replace external
  dependencies with fakes.
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
Code!
• Let’s look at some actual code
TypeMock vs Others
• Some mock frameworks can only mock
  interfaces
• 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 to
  require interfaces to fake
Debate
• Advocates of Testability say you don’t get the
  clean SOLID design of writing for testability
• Should the isolation framework be dictating
  design decisions?
• Design for testability leaves out the majority
  of work… Brownfield applications
TDD and indirectly unit testing
                 research
• "We found that test-first students on average wrote more tests
  and, in turn, students who wrote more tests tended to be more
  productive. We also observed that the minimum quality increased
  linearly with the number of programmer tests, independent of the
  development strategy employed."
• "The external validity of the results could be limited since the
  subjects were students. Runeson [21] compared
  freshmen, graduate, and professional developers and concluded
  that similar improvement trends persisted among the three groups.
  Replicated experiments by Porter
  and Votta [22] and Höst et al. [23] suggest that students may
  provide an adequate model of the professional population."
• Taken from
  http://weblogs.asp.net/rosherove/archive/2008/01/25/research-
  finds-tdd-boosts-developer-productivity.aspx
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 the
  Unhappy Path
• Start out testing by hitting your longest, most
  cyclomatically complex, most critical, or just
  hardest to understand methods.
• Try to reduce the external dependency contact
  points in a class
• Write a test that FAILS first! Write the test before
  the code, or comment out the part that should
  make it succeed.
My Passions
• Tooling anything that makes coding easier or
  more productive
• MVC
• Extensibility

Weitere ähnliche Inhalte

Was ist angesagt?

Benefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldBenefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real World
Dror Helper
 
An Overview of automated testing (1)
An Overview of automated testing (1)An Overview of automated testing (1)
An Overview of automated testing (1)
Rodrigo Lopes
 

Was ist angesagt? (18)

Benefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldBenefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real World
 
TDD In Practice
TDD In PracticeTDD In Practice
TDD In Practice
 
Real Life Unit Testing
Real Life Unit TestingReal Life Unit Testing
Real Life Unit Testing
 
Mixing testing types to improve your testing results
Mixing testing types to improve your testing resultsMixing testing types to improve your testing results
Mixing testing types to improve your testing results
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Test-driven development with Node.js
Test-driven development with Node.jsTest-driven development with Node.js
Test-driven development with Node.js
 
An Overview of automated testing (1)
An Overview of automated testing (1)An Overview of automated testing (1)
An Overview of automated testing (1)
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
Testing JavaScript Applications
Testing JavaScript ApplicationsTesting JavaScript Applications
Testing JavaScript Applications
 
xUnit test patterns 0
xUnit test patterns 0xUnit test patterns 0
xUnit test patterns 0
 
Skillwise Unit Testing
Skillwise Unit TestingSkillwise Unit Testing
Skillwise Unit Testing
 
Unit testing in PHP
Unit testing in PHPUnit testing in PHP
Unit testing in PHP
 
Patterns in Testing
Patterns in TestingPatterns in Testing
Patterns in Testing
 
Automated Testing but like for PowerShell (April 2012)
Automated Testing but like for PowerShell (April 2012)Automated Testing but like for PowerShell (April 2012)
Automated Testing but like for PowerShell (April 2012)
 
Exploratory testing
Exploratory testingExploratory testing
Exploratory testing
 
@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC
 
Introduction to test programming
Introduction to test programmingIntroduction to test programming
Introduction to test programming
 

Andere mochten auch (9)

Artifical intelligence
Artifical intelligenceArtifical intelligence
Artifical intelligence
 
Electric traction system final upload
Electric traction system final uploadElectric traction system final upload
Electric traction system final upload
 
Visit to 400 kV substation, Hadala
Visit to 400 kV substation, HadalaVisit to 400 kV substation, Hadala
Visit to 400 kV substation, Hadala
 
Electric Traction
Electric TractionElectric Traction
Electric Traction
 
SWITCHYARD EQUIPMENTS & PROTECTION SYSTEMS
SWITCHYARD EQUIPMENTS & PROTECTION SYSTEMSSWITCHYARD EQUIPMENTS & PROTECTION SYSTEMS
SWITCHYARD EQUIPMENTS & PROTECTION SYSTEMS
 
Switch yard & Protection
Switch yard & ProtectionSwitch yard & Protection
Switch yard & Protection
 
400kv sub-station-final-ppt-by-mohit
400kv sub-station-final-ppt-by-mohit400kv sub-station-final-ppt-by-mohit
400kv sub-station-final-ppt-by-mohit
 
Underground cables
Underground cablesUnderground cables
Underground cables
 
Electric Traction
Electric Traction Electric Traction
Electric Traction
 

Ähnlich wie Type mock isolator

Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
MaslowB
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
Meilan Ou
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
Alex Borsuk
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
BestBrains
 

Ähnlich wie Type mock isolator (20)

Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
 
CNUG TDD June 2014
CNUG TDD June 2014CNUG TDD June 2014
CNUG TDD June 2014
 
Software testing part
Software testing partSoftware testing part
Software testing part
 
Week 14 Unit Testing.pptx
Week 14  Unit Testing.pptxWeek 14  Unit Testing.pptx
Week 14 Unit Testing.pptx
 
Unit testing
Unit testingUnit testing
Unit testing
 
testing strategies and tactics
 testing strategies and tactics testing strategies and tactics
testing strategies and tactics
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Presentation delex
Presentation delexPresentation delex
Presentation delex
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
Agile Software Testing the Agilogy Way
Agile Software Testing the Agilogy WayAgile Software Testing the Agilogy Way
Agile Software Testing the Agilogy Way
 
Lecture 21
Lecture 21Lecture 21
Lecture 21
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.
 
MDD and the Tautology Problem: Discussion Notes.
MDD and the Tautology Problem: Discussion Notes.MDD and the Tautology Problem: Discussion Notes.
MDD and the Tautology Problem: Discussion Notes.
 
Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
 
Mihai mahulea the zen of test driven development
Mihai mahulea   the zen of test driven developmentMihai mahulea   the zen of test driven development
Mihai mahulea the zen of test driven development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 

Mehr von MaslowB (8)

F# for BLOBA, by brandon d'imperio
F# for BLOBA, by brandon d'imperioF# for BLOBA, by brandon d'imperio
F# for BLOBA, by brandon d'imperio
 
Knockout vs. angular
Knockout vs. angularKnockout vs. angular
Knockout vs. angular
 
Js testing
Js testingJs testing
Js testing
 
What’s new mvc 4
What’s new mvc 4What’s new mvc 4
What’s new mvc 4
 
A clean repository pattern in ef
A clean repository pattern in efA clean repository pattern in ef
A clean repository pattern in ef
 
Metrics
MetricsMetrics
Metrics
 
Mvc presentation
Mvc presentationMvc presentation
Mvc presentation
 
Metaprogramming by brandon
Metaprogramming by brandonMetaprogramming by brandon
Metaprogramming by brandon
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Type mock isolator

  • 1. TypeMock Isolator Mocks/Fakes/Stubs By Brandon D’Imperio ImaginaryDevelopment@gmail.com
  • 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 to fake out deep call chains • My dependencies are static, sealed, or non- public and can’t be faked
  • 3. Jargon/Definitions • Unit Test – Code (usually a method) that runs another piece of code (usually a single method/function in isolation) and checks the correctness of an assumption afterward. If the assumptions are wrong, 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
  • 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. Unit Testing weaknesses • Can not catch integration errors, system-level errors, or non-functional (performance, security, etc) • Additional maintenance • Additional coding • Unit tests may share the same blind spots as the code because they are written by the same developer
  • 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 blind spots
  • 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. What’s a mock/isolation framework? • In order to properly unit test your external dependencies must be replaced. A unit test should ONLY fail because of the code you are testing, otherwise it’s an integration test. • A mock framework is a tool to replace external dependencies with fakes.
  • 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. Code! • Let’s look at some actual code
  • 12. TypeMock vs Others • Some mock frameworks can only mock interfaces • 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 to require interfaces to fake
  • 13. Debate • Advocates of Testability say you don’t get the clean SOLID design of writing for testability • Should the isolation framework be dictating design decisions? • Design for testability leaves out the majority of work… Brownfield applications
  • 14. TDD and indirectly unit testing research • "We found that test-first students on average wrote more tests and, in turn, students who wrote more tests tended to be more productive. We also observed that the minimum quality increased linearly with the number of programmer tests, independent of the development strategy employed." • "The external validity of the results could be limited since the subjects were students. Runeson [21] compared freshmen, graduate, and professional developers and concluded that similar improvement trends persisted among the three groups. Replicated experiments by Porter and Votta [22] and Höst et al. [23] suggest that students may provide an adequate model of the professional population." • Taken from http://weblogs.asp.net/rosherove/archive/2008/01/25/research- finds-tdd-boosts-developer-productivity.aspx
  • 15. More reading… • Martin Fowler – Mocks aren’t stubs • Uncle Bob – TDD Derangement Syndrome
  • 16. Good Practices • Only a single Assert per test • Code a test for both the Happy Path and the Unhappy Path • Start out testing by hitting your longest, most cyclomatically complex, most critical, or just hardest to understand methods. • Try to reduce the external dependency contact points in a class • Write a test that FAILS first! Write the test before the code, or comment out the part that should make it succeed.
  • 17. My Passions • Tooling anything that makes coding easier or more productive • MVC • Extensibility

Hinweis der Redaktion

  1. Reference: http://weblogs.asp.net/rosherove/archive/2007/04/26/choosing-a-mock-object-framework.aspxNmock: http://www.nmock.org/cheatsheet.html