SlideShare a Scribd company logo
Tech Podcast Night
The art of unit testing ch5-6
by mia
關
於
我
Microsoft Data Platform MVP
Data Scientist
Computer Vision/Algorithm Research
mia5419@gmail.com
https://github.com/pymia/
https://www.linkedin.com/in/mia-chang/
Tech Podcast Night
https://www.facebook.com/TechPodcastNight/
Mia Chang
Chap 5
● 5.1 Why use isolation frameworks?
● 5.2 Dynamically creating a fake object
● 5.3 Simulating fake values
● 5.4 Testing for event-related activities
● 5.5 Current isolation frameworks for .NET
● 5.6 Advantages and traps of isolation frameworks
● 5.7 Summary
Chap 6
● 6.1 Constrained and unconstrained frameworks
● 6.2 Values of good isolation frameworks
● 6.3 Features supporting future-proofing and usability
● 6.4 Isolation framework design antipatterns
● 6.5 Summary
Agenda
5.1
DEFINITION An isolation framework is a set of programmable API s that makes creating
fake objects much simpler, faster, and shorter than hand-coding them.
- Using isolation frameworks instead of writing mocks and stubs manually, as in previous
chapters, has several advantages that make developing more elegant and complex
tests easier, faster, and less error prone.
The best way to understand the value of an isolation framework is to see a problem
and its solution. One problem that might occur when using handwritten mocks and
stubs is repetitive code.
5.1
Assume you have an interface a little
more complicated than the ones shown
so far:
5.2
DEFINITION A dynamic fake object is any stub or mock that’s created at runtime
without needing to use a handwritten (hardcoded) implementation of
that object.
Next, we’ll look at NSubstitute and see how it can help you overcome some of the
problems just discussed.
5.3
arrange
act
assert
■ Easy to create the object with the
expected properties.
■ Test all the properties of the object in
question.
■ You know the exact values of each
property, fully.
■ The Equals() method is implemented
correctly on the two objects being
compared.
ch5 summary
Mocks should be used only when there’s no other way to test the implementation,
because they eventually lead to tests that are harder to maintain if you’re not careful.
If more than 5% of your tests have mock objects (not stubs), you might be over specifying things.
Learn how to use the advanced features of an isolation framework such as NSub, and you can pretty
much make sure that anything happens or doesn’t happen in your tests. All you need is for your code to
be testable.
ch5 summary
don’t repeat → more readable
In the next chapter, we’ll dig deeper into isolation frameworks
and see how their design and underlying implementation affect their abilities.
Chap 5
● 5.1 Why use isolation frameworks?
● 5.2 Dynamically creating a fake object
● 5.3 Simulating fake values
● 5.4 Testing for event-related activities
● 5.5 Current isolation frameworks for .NET
● 5.6 Advantages and traps of isolation frameworks
● 5.7 Summary
Chap 6
● 6.1 Constrained and unconstrained frameworks
● 6.2 Values of good isolation frameworks
● 6.3 Features supporting future-proofing and usability
● 6.4 Isolation framework design antipatterns
● 6.5 Summary
Agenda
6.1 Constrained and unconstrained frameworks
Constrained frameworks usually work by generating code at runtime that inherits
and overrides interfaces or base classes, just as you did in the previous chapter,
the code you want to fake has to be public and inheritable (nonsealed),
has to have a public constructor, or should be an interface.
Unconstrained frameworks: Microsoft Fakes
https://docs.microsoft.com/en-us/visualstudio/test/isolating-code-under-test-with-microsoft-fakes
Pros
■ You can write unit tests for previously untestable
code
■ You can fake third-party systems that you can’t
control and that are potentially very hard to test with.
■ You can choose your own level of design, rather
than be forced into specific patterns.
Cons
■ If you don’t pay close attention,
you can fake your way into a corner by faking things
that aren’t needed.
■ If you don’t pay close attention, some tests can
become unmaintainable because you’re faking APIs
that you don’t own.
Fake a low-enough level of an API in a framework,
it’s very unlikely to change in the future. The deeper
an API is, the more likely many things are built on
top of it.
https://docs.microsoft.com/en-us/visualstudio/test/using-shims-to-isolate-your-application-from-other-as
semblies-for-unit-testing
6.2 Values of good isolation framework
Good isolation frameworks have two values:
■ Future-proofing
■ Usability
Here are some features that support these values
in the newer frameworks:
■ Recursive fakes
■ Ignored arguments by default
■ Wide faking
■ Nonstrict behavior of
6.3 Features supporting future-proofing and usability
Here are some features that support these values
in the newer frameworks:
■ Recursive fakes
■ Ignored arguments by default
■ Wide faking
■ Nonstrict behavior of
Not all isolation frameworks allow recursive fakes, so check for this ability on your favorite
framework. As far as I know, only .NET frameworks currently even consider this ability. I
wish this existed in other languages as well.
6.4 Isolation framework design antipatterns
■ Concept confusion
■ Record and replay
■ Sticky behavior
■ Complex syntax
6.4 Isolation framework design antipatterns
■ Concept confusion
■ Record and replay
■ Sticky behavior
■ Complex syntax
6.4 Isolation framework design antipatterns
■ Concept confusion
■ Record and replay
■ Sticky behavior
■ Complex syntax
ch6 summary
Isolation frameworks are divided into two categories: constrained and unconstrained frameworks.
The core techniques for writing unit tests.
DeepTest: Automated Testing of
Deep-Neural-Network-driven Autonomous Cars ■ Testing of driver assistance systems.
■ Testing and verification of machine learning.
■ Adversarial machine learning
■ Test amplification.
■ Metamorphic testing.

More Related Content

What's hot

MVVM Light for UWP
MVVM Light for UWPMVVM Light for UWP
MVVM Light for UWP
Robert Iagar
 
Why Localization Standards Fail (TAUS User Conference 2013)
Why Localization Standards Fail (TAUS User Conference 2013)Why Localization Standards Fail (TAUS User Conference 2013)
Why Localization Standards Fail (TAUS User Conference 2013)
Chase Tingley
 
AATC2016: Exploratory testing an API
AATC2016: Exploratory testing an APIAATC2016: Exploratory testing an API
AATC2016: Exploratory testing an API
Maaret Pyhäjärvi
 
Chaos Engineering Talk at DevOps Days Austin
Chaos Engineering Talk at DevOps Days AustinChaos Engineering Talk at DevOps Days Austin
Chaos Engineering Talk at DevOps Days Austin
matthewbrahms
 
Agile2015: Explore with Intent - Self-Management
Agile2015: Explore with Intent - Self-ManagementAgile2015: Explore with Intent - Self-Management
Agile2015: Explore with Intent - Self-Management
Maaret Pyhäjärvi
 
Test Essentials @mdevcon 2012
Test Essentials @mdevcon 2012Test Essentials @mdevcon 2012
Test Essentials @mdevcon 2012Maxim Zaks
 
Freelance symfony framework
Freelance symfony frameworkFreelance symfony framework
Freelance symfony framework
anikanielsen
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven developmentEinar Ingebrigtsen
 
Unit testing (workshop)
Unit testing (workshop)Unit testing (workshop)
Unit testing (workshop)Foyzul Karim
 
13 Test Automation Practices You Should be Afraid Of
13 Test Automation Practices You Should be Afraid Of13 Test Automation Practices You Should be Afraid Of
13 Test Automation Practices You Should be Afraid Of
Joe Colantonio
 
Get Your Database Under Control
Get Your Database Under ControlGet Your Database Under Control
Get Your Database Under Control
Grant Fritchey
 

What's hot (11)

MVVM Light for UWP
MVVM Light for UWPMVVM Light for UWP
MVVM Light for UWP
 
Why Localization Standards Fail (TAUS User Conference 2013)
Why Localization Standards Fail (TAUS User Conference 2013)Why Localization Standards Fail (TAUS User Conference 2013)
Why Localization Standards Fail (TAUS User Conference 2013)
 
AATC2016: Exploratory testing an API
AATC2016: Exploratory testing an APIAATC2016: Exploratory testing an API
AATC2016: Exploratory testing an API
 
Chaos Engineering Talk at DevOps Days Austin
Chaos Engineering Talk at DevOps Days AustinChaos Engineering Talk at DevOps Days Austin
Chaos Engineering Talk at DevOps Days Austin
 
Agile2015: Explore with Intent - Self-Management
Agile2015: Explore with Intent - Self-ManagementAgile2015: Explore with Intent - Self-Management
Agile2015: Explore with Intent - Self-Management
 
Test Essentials @mdevcon 2012
Test Essentials @mdevcon 2012Test Essentials @mdevcon 2012
Test Essentials @mdevcon 2012
 
Freelance symfony framework
Freelance symfony frameworkFreelance symfony framework
Freelance symfony framework
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
 
Unit testing (workshop)
Unit testing (workshop)Unit testing (workshop)
Unit testing (workshop)
 
13 Test Automation Practices You Should be Afraid Of
13 Test Automation Practices You Should be Afraid Of13 Test Automation Practices You Should be Afraid Of
13 Test Automation Practices You Should be Afraid Of
 
Get Your Database Under Control
Get Your Database Under ControlGet Your Database Under Control
Get Your Database Under Control
 

Similar to The Art of Unit Testing Ch5-6

Testing java microservices: from development to production
Testing java microservices: from development to productionTesting java microservices: from development to production
Testing java microservices: from development to production
Abraham Marin-Perez
 
Testing Java Microservices: From Development to Production
Testing Java Microservices: From Development to ProductionTesting Java Microservices: From Development to Production
Testing Java Microservices: From Development to Production
Daniel Bryant
 
Opticon18: Developer Night
Opticon18: Developer NightOpticon18: Developer Night
Opticon18: Developer Night
Optimizely
 
Web frameworks
Web frameworksWeb frameworks
Web frameworks
Arafat Hossan
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing FundamentalsRichard Paul
 
Devoxx UK 2019: "Testing Java Microservices: From Development to Production
Devoxx UK 2019: "Testing Java Microservices: From Development to ProductionDevoxx UK 2019: "Testing Java Microservices: From Development to Production
Devoxx UK 2019: "Testing Java Microservices: From Development to Production
Daniel Bryant
 
Cypress Best Pratices for Test Automation
Cypress Best Pratices for Test AutomationCypress Best Pratices for Test Automation
Cypress Best Pratices for Test Automation
Knoldus Inc.
 
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
João Pedro Martins
 
CodeOne SF 2018: "Testing Java Microservices: From Development to Production"
CodeOne SF 2018: "Testing Java Microservices: From Development to Production"CodeOne SF 2018: "Testing Java Microservices: From Development to Production"
CodeOne SF 2018: "Testing Java Microservices: From Development to Production"
Daniel Bryant
 
How can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdfHow can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdf
Mindfire LLC
 
Automation Framework Design
Automation Framework DesignAutomation Framework Design
Automation Framework DesignKunal Saxena
 
Tests immutable when refactoring - SegFault Unconference Cracow 2019
Tests immutable when refactoring - SegFault Unconference Cracow 2019Tests immutable when refactoring - SegFault Unconference Cracow 2019
Tests immutable when refactoring - SegFault Unconference Cracow 2019
Grzegorz Miejski
 
Microsoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable CodeMicrosoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable Code
Aleksandar Bozinovski
 
Unit Tests with Microsoft Fakes
Unit Tests with Microsoft FakesUnit Tests with Microsoft Fakes
Unit Tests with Microsoft Fakes
Aleksandar Bozinovski
 
jDriver Presentation
jDriver PresentationjDriver Presentation
jDriver Presentation
freelancer_testautomation
 
Centralized test automation framework implementation
Centralized test automation framework implementationCentralized test automation framework implementation
Centralized test automation framework implementation
Bharathi Krishnamurthi
 
deliver:Agile 2019 "Testing Microservices: From Development to Production
deliver:Agile 2019 "Testing Microservices: From Development to Productiondeliver:Agile 2019 "Testing Microservices: From Development to Production
deliver:Agile 2019 "Testing Microservices: From Development to Production
Daniel Bryant
 
Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...
Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...
Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...
Applitools
 
odsc_2023.pdf
odsc_2023.pdfodsc_2023.pdf
odsc_2023.pdf
Sanghamitra Deb
 
Test automation within a scrum process
Test automation within a scrum processTest automation within a scrum process
Test automation within a scrum process
Kushan Shalindra Amarasiri - Technical QE Specialist
 

Similar to The Art of Unit Testing Ch5-6 (20)

Testing java microservices: from development to production
Testing java microservices: from development to productionTesting java microservices: from development to production
Testing java microservices: from development to production
 
Testing Java Microservices: From Development to Production
Testing Java Microservices: From Development to ProductionTesting Java Microservices: From Development to Production
Testing Java Microservices: From Development to Production
 
Opticon18: Developer Night
Opticon18: Developer NightOpticon18: Developer Night
Opticon18: Developer Night
 
Web frameworks
Web frameworksWeb frameworks
Web frameworks
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
 
Devoxx UK 2019: "Testing Java Microservices: From Development to Production
Devoxx UK 2019: "Testing Java Microservices: From Development to ProductionDevoxx UK 2019: "Testing Java Microservices: From Development to Production
Devoxx UK 2019: "Testing Java Microservices: From Development to Production
 
Cypress Best Pratices for Test Automation
Cypress Best Pratices for Test AutomationCypress Best Pratices for Test Automation
Cypress Best Pratices for Test Automation
 
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
 
CodeOne SF 2018: "Testing Java Microservices: From Development to Production"
CodeOne SF 2018: "Testing Java Microservices: From Development to Production"CodeOne SF 2018: "Testing Java Microservices: From Development to Production"
CodeOne SF 2018: "Testing Java Microservices: From Development to Production"
 
How can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdfHow can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdf
 
Automation Framework Design
Automation Framework DesignAutomation Framework Design
Automation Framework Design
 
Tests immutable when refactoring - SegFault Unconference Cracow 2019
Tests immutable when refactoring - SegFault Unconference Cracow 2019Tests immutable when refactoring - SegFault Unconference Cracow 2019
Tests immutable when refactoring - SegFault Unconference Cracow 2019
 
Microsoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable CodeMicrosoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable Code
 
Unit Tests with Microsoft Fakes
Unit Tests with Microsoft FakesUnit Tests with Microsoft Fakes
Unit Tests with Microsoft Fakes
 
jDriver Presentation
jDriver PresentationjDriver Presentation
jDriver Presentation
 
Centralized test automation framework implementation
Centralized test automation framework implementationCentralized test automation framework implementation
Centralized test automation framework implementation
 
deliver:Agile 2019 "Testing Microservices: From Development to Production
deliver:Agile 2019 "Testing Microservices: From Development to Productiondeliver:Agile 2019 "Testing Microservices: From Development to Production
deliver:Agile 2019 "Testing Microservices: From Development to Production
 
Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...
Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...
Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...
 
odsc_2023.pdf
odsc_2023.pdfodsc_2023.pdf
odsc_2023.pdf
 
Test automation within a scrum process
Test automation within a scrum processTest automation within a scrum process
Test automation within a scrum process
 

More from Mia Chang

Running the first automatic speech recognition (ASR) model with HuggingFace -...
Running the first automatic speech recognition (ASR) model with HuggingFace -...Running the first automatic speech recognition (ASR) model with HuggingFace -...
Running the first automatic speech recognition (ASR) model with HuggingFace -...
Mia Chang
 
7 steps to AI production - global azure bootcamp 2020 Koln
7 steps to AI production - global azure bootcamp 2020 Koln7 steps to AI production - global azure bootcamp 2020 Koln
7 steps to AI production - global azure bootcamp 2020 Koln
Mia Chang
 
TensorFlow Lite for mobile & IoT
TensorFlow Lite for mobile & IoT   TensorFlow Lite for mobile & IoT
TensorFlow Lite for mobile & IoT
Mia Chang
 
DPS2019 data scientist in the real estate industry
DPS2019 data scientist in the real estate industry DPS2019 data scientist in the real estate industry
DPS2019 data scientist in the real estate industry
Mia Chang
 
Leverage the power of machine learning on windows
Leverage the power of machine learning on windowsLeverage the power of machine learning on windows
Leverage the power of machine learning on windows
Mia Chang
 
Develop computer vision applications with azure computer vision api
Develop computer vision applications with azure computer vision apiDevelop computer vision applications with azure computer vision api
Develop computer vision applications with azure computer vision api
Mia Chang
 
Deploy Deep Learning Application with Azure Container Instance - Devdays2018
Deploy Deep Learning Application with Azure Container Instance - Devdays2018Deploy Deep Learning Application with Azure Container Instance - Devdays2018
Deploy Deep Learning Application with Azure Container Instance - Devdays2018
Mia Chang
 
What's AI, Machine Learning and Deep Learning - Talk @NCCU python 讀書會
What's AI, Machine Learning and Deep Learning - Talk @NCCU python 讀書會What's AI, Machine Learning and Deep Learning - Talk @NCCU python 讀書會
What's AI, Machine Learning and Deep Learning - Talk @NCCU python 讀書會
Mia Chang
 
Play Kaggle with R, Facebook V: Predicting Check Ins
Play Kaggle with R, Facebook V: Predicting Check InsPlay Kaggle with R, Facebook V: Predicting Check Ins
Play Kaggle with R, Facebook V: Predicting Check Ins
Mia Chang
 
twMVC#29 -Learning Machine Learning with Movie Recommendation
twMVC#29 -Learning Machine Learning with Movie RecommendationtwMVC#29 -Learning Machine Learning with Movie Recommendation
twMVC#29 -Learning Machine Learning with Movie Recommendation
Mia Chang
 

More from Mia Chang (10)

Running the first automatic speech recognition (ASR) model with HuggingFace -...
Running the first automatic speech recognition (ASR) model with HuggingFace -...Running the first automatic speech recognition (ASR) model with HuggingFace -...
Running the first automatic speech recognition (ASR) model with HuggingFace -...
 
7 steps to AI production - global azure bootcamp 2020 Koln
7 steps to AI production - global azure bootcamp 2020 Koln7 steps to AI production - global azure bootcamp 2020 Koln
7 steps to AI production - global azure bootcamp 2020 Koln
 
TensorFlow Lite for mobile & IoT
TensorFlow Lite for mobile & IoT   TensorFlow Lite for mobile & IoT
TensorFlow Lite for mobile & IoT
 
DPS2019 data scientist in the real estate industry
DPS2019 data scientist in the real estate industry DPS2019 data scientist in the real estate industry
DPS2019 data scientist in the real estate industry
 
Leverage the power of machine learning on windows
Leverage the power of machine learning on windowsLeverage the power of machine learning on windows
Leverage the power of machine learning on windows
 
Develop computer vision applications with azure computer vision api
Develop computer vision applications with azure computer vision apiDevelop computer vision applications with azure computer vision api
Develop computer vision applications with azure computer vision api
 
Deploy Deep Learning Application with Azure Container Instance - Devdays2018
Deploy Deep Learning Application with Azure Container Instance - Devdays2018Deploy Deep Learning Application with Azure Container Instance - Devdays2018
Deploy Deep Learning Application with Azure Container Instance - Devdays2018
 
What's AI, Machine Learning and Deep Learning - Talk @NCCU python 讀書會
What's AI, Machine Learning and Deep Learning - Talk @NCCU python 讀書會What's AI, Machine Learning and Deep Learning - Talk @NCCU python 讀書會
What's AI, Machine Learning and Deep Learning - Talk @NCCU python 讀書會
 
Play Kaggle with R, Facebook V: Predicting Check Ins
Play Kaggle with R, Facebook V: Predicting Check InsPlay Kaggle with R, Facebook V: Predicting Check Ins
Play Kaggle with R, Facebook V: Predicting Check Ins
 
twMVC#29 -Learning Machine Learning with Movie Recommendation
twMVC#29 -Learning Machine Learning with Movie RecommendationtwMVC#29 -Learning Machine Learning with Movie Recommendation
twMVC#29 -Learning Machine Learning with Movie Recommendation
 

Recently uploaded

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 

Recently uploaded (20)

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 

The Art of Unit Testing Ch5-6

  • 1. Tech Podcast Night The art of unit testing ch5-6 by mia
  • 2. 關 於 我 Microsoft Data Platform MVP Data Scientist Computer Vision/Algorithm Research mia5419@gmail.com https://github.com/pymia/ https://www.linkedin.com/in/mia-chang/ Tech Podcast Night https://www.facebook.com/TechPodcastNight/ Mia Chang
  • 3. Chap 5 ● 5.1 Why use isolation frameworks? ● 5.2 Dynamically creating a fake object ● 5.3 Simulating fake values ● 5.4 Testing for event-related activities ● 5.5 Current isolation frameworks for .NET ● 5.6 Advantages and traps of isolation frameworks ● 5.7 Summary Chap 6 ● 6.1 Constrained and unconstrained frameworks ● 6.2 Values of good isolation frameworks ● 6.3 Features supporting future-proofing and usability ● 6.4 Isolation framework design antipatterns ● 6.5 Summary Agenda
  • 4. 5.1 DEFINITION An isolation framework is a set of programmable API s that makes creating fake objects much simpler, faster, and shorter than hand-coding them. - Using isolation frameworks instead of writing mocks and stubs manually, as in previous chapters, has several advantages that make developing more elegant and complex tests easier, faster, and less error prone. The best way to understand the value of an isolation framework is to see a problem and its solution. One problem that might occur when using handwritten mocks and stubs is repetitive code.
  • 5. 5.1 Assume you have an interface a little more complicated than the ones shown so far:
  • 6. 5.2 DEFINITION A dynamic fake object is any stub or mock that’s created at runtime without needing to use a handwritten (hardcoded) implementation of that object. Next, we’ll look at NSubstitute and see how it can help you overcome some of the problems just discussed.
  • 7. 5.3
  • 8.
  • 9.
  • 10.
  • 11.
  • 12. arrange act assert ■ Easy to create the object with the expected properties. ■ Test all the properties of the object in question. ■ You know the exact values of each property, fully. ■ The Equals() method is implemented correctly on the two objects being compared.
  • 13.
  • 14.
  • 15. ch5 summary Mocks should be used only when there’s no other way to test the implementation, because they eventually lead to tests that are harder to maintain if you’re not careful. If more than 5% of your tests have mock objects (not stubs), you might be over specifying things. Learn how to use the advanced features of an isolation framework such as NSub, and you can pretty much make sure that anything happens or doesn’t happen in your tests. All you need is for your code to be testable.
  • 16. ch5 summary don’t repeat → more readable In the next chapter, we’ll dig deeper into isolation frameworks and see how their design and underlying implementation affect their abilities.
  • 17. Chap 5 ● 5.1 Why use isolation frameworks? ● 5.2 Dynamically creating a fake object ● 5.3 Simulating fake values ● 5.4 Testing for event-related activities ● 5.5 Current isolation frameworks for .NET ● 5.6 Advantages and traps of isolation frameworks ● 5.7 Summary Chap 6 ● 6.1 Constrained and unconstrained frameworks ● 6.2 Values of good isolation frameworks ● 6.3 Features supporting future-proofing and usability ● 6.4 Isolation framework design antipatterns ● 6.5 Summary Agenda
  • 18. 6.1 Constrained and unconstrained frameworks Constrained frameworks usually work by generating code at runtime that inherits and overrides interfaces or base classes, just as you did in the previous chapter, the code you want to fake has to be public and inheritable (nonsealed), has to have a public constructor, or should be an interface. Unconstrained frameworks: Microsoft Fakes https://docs.microsoft.com/en-us/visualstudio/test/isolating-code-under-test-with-microsoft-fakes
  • 19. Pros ■ You can write unit tests for previously untestable code ■ You can fake third-party systems that you can’t control and that are potentially very hard to test with. ■ You can choose your own level of design, rather than be forced into specific patterns. Cons ■ If you don’t pay close attention, you can fake your way into a corner by faking things that aren’t needed. ■ If you don’t pay close attention, some tests can become unmaintainable because you’re faking APIs that you don’t own. Fake a low-enough level of an API in a framework, it’s very unlikely to change in the future. The deeper an API is, the more likely many things are built on top of it. https://docs.microsoft.com/en-us/visualstudio/test/using-shims-to-isolate-your-application-from-other-as semblies-for-unit-testing
  • 20. 6.2 Values of good isolation framework Good isolation frameworks have two values: ■ Future-proofing ■ Usability Here are some features that support these values in the newer frameworks: ■ Recursive fakes ■ Ignored arguments by default ■ Wide faking ■ Nonstrict behavior of
  • 21. 6.3 Features supporting future-proofing and usability Here are some features that support these values in the newer frameworks: ■ Recursive fakes ■ Ignored arguments by default ■ Wide faking ■ Nonstrict behavior of Not all isolation frameworks allow recursive fakes, so check for this ability on your favorite framework. As far as I know, only .NET frameworks currently even consider this ability. I wish this existed in other languages as well.
  • 22. 6.4 Isolation framework design antipatterns ■ Concept confusion ■ Record and replay ■ Sticky behavior ■ Complex syntax
  • 23. 6.4 Isolation framework design antipatterns ■ Concept confusion ■ Record and replay ■ Sticky behavior ■ Complex syntax
  • 24. 6.4 Isolation framework design antipatterns ■ Concept confusion ■ Record and replay ■ Sticky behavior ■ Complex syntax
  • 25. ch6 summary Isolation frameworks are divided into two categories: constrained and unconstrained frameworks. The core techniques for writing unit tests.
  • 26. DeepTest: Automated Testing of Deep-Neural-Network-driven Autonomous Cars ■ Testing of driver assistance systems. ■ Testing and verification of machine learning. ■ Adversarial machine learning ■ Test amplification. ■ Metamorphic testing.