SlideShare a Scribd company logo
1 of 8
.NET Unit Testing




                                                                                    http://wp.me/pjaaL-1o
                  with
          Microsoft Fakes (Beta)
@lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance
June 22-24, 2012
http://givecampmemphis.org

@lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance
Why should I be unit testing?
• You have:
  • No idea what you’re doing to your code
  • No idea what they’re doing to your code
  • No idea what’s going to change in the future
• You need:
  • To protect your code from you
  • To protect your code from them
  • To protect today’s work from tomorrow’s changes


     @lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance
A “unit” is what you isolate.
• Your method has dependencies:
  • The logging thing (the analytics thing?)
  • The database thing (the web service thing?)
  • The thing that gets input from the UI
• You need:
  • To test your unit’s logic, not dependencies
  • To control your dependencies
  • To test all logic anytime the code changes


     @lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance
Keep the “unit”. Lose the rest.
• “Faking” – also known as:
  • Stubbing – test classes instead of dependencies
  • Mocking – frameworks instead of dependencies
  • Isolating – what’s my “unit”? Key question!
• You need:
  • To remove the unknowns of dependencies
  • To test the “unit” in different scenarios
  • To design your code independent of testing tools


     @lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance
How do I use Microsoft Fakes?
• Stubs (similar to Moq, Rhino Mocks, etc.)
    • faking “well-designed” dependencies (recommended)
• Shims (similar to Isolator, Just Mock Pro, etc.)
    • faking “poorly-designed” dependencies (powerful)
    • performance overhead; runtime code rewriting
• Verify
    • the “unit” used dependencies as expected
    • no verify support (yet?)


         @lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance
Onto the Code!

 @lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance
Thank You for letting me share.
• Say Hello!
  •    Blog: http://notworthrepeating.blogspot.com (slides/code)
  •    Google+: http://gplus.to/lance Twitter: @lancehilliard
  •    Email: lance@digitalcreations.cc
• Relevant Reading
  •    Isolating Unit Test Methods with Microsoft Fakes (MSDN)
       http://tinyurl.com/msfakes
       •        Using stubs to isolate calls to virtual functions
       •        Using shims to isolate calls to non-virtual functions
       •        Code generation, compilation, and naming conventions

• Recommended Reading
  •    The Clean Coder: A Code of Conduct for Professional Programmers
       http://tinyurl.com/thecleancoder

           @lancehilliard -- .NET Unit Testing with Microsoft Fakes (Beta) -- http://gplus.to/lance

More Related Content

What's hot

Make sure your code works
Make sure your code worksMake sure your code works
Make sure your code works
Henrik Skupin
 

What's hot (20)

Architecture of automated test cases for legacy applications
Architecture of automated test cases for legacy applicationsArchitecture of automated test cases for legacy applications
Architecture of automated test cases for legacy applications
 
Introduction to Robot Framework
Introduction to Robot FrameworkIntroduction to Robot Framework
Introduction to Robot Framework
 
Ruin your life using robot framework
Ruin your life using robot frameworkRuin your life using robot framework
Ruin your life using robot framework
 
Make sure your code works
Make sure your code worksMake sure your code works
Make sure your code works
 
Robot framework Gowthami Goli
Robot framework Gowthami GoliRobot framework Gowthami Goli
Robot framework Gowthami Goli
 
Robot framework - Lord of the Rings
Robot framework - Lord of the RingsRobot framework - Lord of the Rings
Robot framework - Lord of the Rings
 
How does Java 8 exert hidden power on Test Automation?
How does Java 8 exert hidden power on Test Automation?How does Java 8 exert hidden power on Test Automation?
How does Java 8 exert hidden power on Test Automation?
 
Robot Framework Introduction & Sauce Labs Integration
Robot Framework Introduction & Sauce Labs IntegrationRobot Framework Introduction & Sauce Labs Integration
Robot Framework Introduction & Sauce Labs Integration
 
Rails automatic test driven development
Rails automatic test driven developmentRails automatic test driven development
Rails automatic test driven development
 
Azphp phpunit-jenkins
Azphp phpunit-jenkinsAzphp phpunit-jenkins
Azphp phpunit-jenkins
 
How to make your functional tests really quick
How to make your functional tests really quickHow to make your functional tests really quick
How to make your functional tests really quick
 
Luis Correia - Instituto de Informática - OSL19
Luis Correia - Instituto de Informática - OSL19Luis Correia - Instituto de Informática - OSL19
Luis Correia - Instituto de Informática - OSL19
 
Meetup AngularJS Rio - Testes e2e para apps AngularJS com Protractor
Meetup AngularJS Rio - Testes e2e para apps AngularJS com ProtractorMeetup AngularJS Rio - Testes e2e para apps AngularJS com Protractor
Meetup AngularJS Rio - Testes e2e para apps AngularJS com Protractor
 
Continuous integration & deployment
Continuous integration & deploymentContinuous integration & deployment
Continuous integration & deployment
 
AQA TALKS 4 - AUTOMATION TEST REPORTER
AQA TALKS 4 - AUTOMATION TEST REPORTERAQA TALKS 4 - AUTOMATION TEST REPORTER
AQA TALKS 4 - AUTOMATION TEST REPORTER
 
Increase selenium tests stability via java script
Increase selenium tests stability via java scriptIncrease selenium tests stability via java script
Increase selenium tests stability via java script
 
Selenium Camp 2016 - Effective UI tests scaling on Java
Selenium Camp 2016 - Effective UI tests scaling on JavaSelenium Camp 2016 - Effective UI tests scaling on Java
Selenium Camp 2016 - Effective UI tests scaling on Java
 
The Art of Unit Testing Ch5-6
The Art of Unit Testing Ch5-6The Art of Unit Testing Ch5-6
The Art of Unit Testing Ch5-6
 
Cypress - Best Practices
Cypress - Best PracticesCypress - Best Practices
Cypress - Best Practices
 
Android lint presentation
Android lint presentationAndroid lint presentation
Android lint presentation
 

Similar to .NET Unit Testing w/ Microsoft Fakes (TechCamp Memphis Spring 2012)

Php com con-2011
Php com con-2011Php com con-2011
Php com con-2011
LB Denker
 

Similar to .NET Unit Testing w/ Microsoft Fakes (TechCamp Memphis Spring 2012) (20)

How do you tame a big ball of mud? One test at a time.
How do you tame a big ball of mud? One test at a time.How do you tame a big ball of mud? One test at a time.
How do you tame a big ball of mud? One test at a time.
 
JavaScript + Jenkins = Winning!
JavaScript + Jenkins = Winning!JavaScript + Jenkins = Winning!
JavaScript + Jenkins = Winning!
 
Unit Testing in JavaScript
Unit Testing in JavaScriptUnit Testing in JavaScript
Unit Testing in JavaScript
 
Effective .NET Core Unit Testing with SQLite and Dapper
Effective .NET Core Unit Testing with SQLite and DapperEffective .NET Core Unit Testing with SQLite and Dapper
Effective .NET Core Unit Testing with SQLite and Dapper
 
Meetup 24/3/2016 - Node.js User Group Belgium
Meetup 24/3/2016 - Node.js User Group BelgiumMeetup 24/3/2016 - Node.js User Group Belgium
Meetup 24/3/2016 - Node.js User Group Belgium
 
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...
 
Effective .NET Core Unit Testing with SQLite and Dapper
Effective .NET Core Unit Testing with SQLite and DapperEffective .NET Core Unit Testing with SQLite and Dapper
Effective .NET Core Unit Testing with SQLite and Dapper
 
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
 
Here Be Dragons – Advanced JavaScript Debugging
Here Be Dragons – Advanced JavaScript DebuggingHere Be Dragons – Advanced JavaScript Debugging
Here Be Dragons – Advanced JavaScript Debugging
 
FITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript Debugging
 
Php com con-2011
Php com con-2011Php com con-2011
Php com con-2011
 
Integration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubsIntegration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubs
 
Static Code Analysis and AutoLint
Static Code Analysis and AutoLintStatic Code Analysis and AutoLint
Static Code Analysis and AutoLint
 
Securing the continuous integration
Securing the continuous integrationSecuring the continuous integration
Securing the continuous integration
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
DBmaestro's State of the Database Continuous Delivery Survey- Findings Revealed
DBmaestro's State of the Database Continuous Delivery Survey- Findings RevealedDBmaestro's State of the Database Continuous Delivery Survey- Findings Revealed
DBmaestro's State of the Database Continuous Delivery Survey- Findings Revealed
 
Agile Software Testing the Agilogy Way
Agile Software Testing the Agilogy WayAgile Software Testing the Agilogy Way
Agile Software Testing the Agilogy Way
 
An Introduction To Software Development - Testing, Continuous integration
An Introduction To Software Development - Testing, Continuous integrationAn Introduction To Software Development - Testing, Continuous integration
An Introduction To Software Development - Testing, Continuous integration
 
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+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@
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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...
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
+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...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 

.NET Unit Testing w/ Microsoft Fakes (TechCamp Memphis Spring 2012)

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