SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

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 WorldDror Helper
 
Real Life Unit Testing
Real Life Unit TestingReal Life Unit Testing
Real Life Unit TestingDror Helper
 
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 resultsPractiTest
 
Test-driven development with Node.js
Test-driven development with Node.jsTest-driven development with Node.js
Test-driven development with Node.jsMirko Kiefer
 
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
 
Testing JavaScript Applications
Testing JavaScript ApplicationsTesting JavaScript Applications
Testing JavaScript ApplicationsMuhammad Samu
 
Patterns in Testing
Patterns in TestingPatterns in Testing
Patterns in TestingJoe Chavez
 
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)Rob Reynolds
 
@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPECWojciech Bulaty
 
Introduction to test programming
Introduction to test programmingIntroduction to test programming
Introduction to test programmingopenfinanceDev
 

La actualidad más candente (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
 

Destacado

Artifical intelligence
Artifical intelligenceArtifical intelligence
Artifical intelligenceBishal Rimal
 
Electric traction system final upload
Electric traction system final uploadElectric traction system final upload
Electric traction system final uploadBishal Rimal
 
Visit to 400 kV substation, Hadala
Visit to 400 kV substation, HadalaVisit to 400 kV substation, Hadala
Visit to 400 kV substation, HadalaNandan Desai
 
Electric Traction
Electric TractionElectric Traction
Electric TractionNawaz Nz
 
SWITCHYARD EQUIPMENTS & PROTECTION SYSTEMS
SWITCHYARD EQUIPMENTS & PROTECTION SYSTEMSSWITCHYARD EQUIPMENTS & PROTECTION SYSTEMS
SWITCHYARD EQUIPMENTS & PROTECTION SYSTEMSPartha Parida
 
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-mohitMohit Awasthi
 
Underground cables
Underground cablesUnderground cables
Underground cablesAnu71
 
Electric Traction
Electric Traction Electric Traction
Electric Traction ZunAib Ali
 

Destacado (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
 

Similar a Type mock isolator

Type mock isolator
Type mock isolatorType mock isolator
Type mock isolatorMaslowB
 
Software testing part
Software testing partSoftware testing part
Software testing partPreeti Mishra
 
Week 14 Unit Testing.pptx
Week 14  Unit Testing.pptxWeek 14  Unit Testing.pptx
Week 14 Unit Testing.pptxmianshafa
 
testing strategies and tactics
 testing strategies and tactics testing strategies and tactics
testing strategies and tacticsPreeti Mishra
 
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...AgileNetwork
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@Alex Borsuk
 
Agile Software Testing the Agilogy Way
Agile Software Testing the Agilogy WayAgile Software Testing the Agilogy Way
Agile Software Testing the Agilogy WayJordi Pradel
 
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.Malinda Kapuruge
 
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.Bob Binder
 
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)Abhijeet Vaikar
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated TestingLars Thorup
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testingBestBrains
 
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 developmentCodecamp Romania
 

Similar a 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
 

Más de MaslowB

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'imperioMaslowB
 
Knockout vs. angular
Knockout vs. angularKnockout vs. angular
Knockout vs. angularMaslowB
 
Js testing
Js testingJs testing
Js testingMaslowB
 
What’s new mvc 4
What’s new mvc 4What’s new mvc 4
What’s new mvc 4MaslowB
 
A clean repository pattern in ef
A clean repository pattern in efA clean repository pattern in ef
A clean repository pattern in efMaslowB
 
Mvc presentation
Mvc presentationMvc presentation
Mvc presentationMaslowB
 
Metaprogramming by brandon
Metaprogramming by brandonMetaprogramming by brandon
Metaprogramming by brandonMaslowB
 

Más de 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
 

Último

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Último (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

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

Notas del editor

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