SlideShare une entreprise Scribd logo
1  sur  8
Unit testing,mocking &tdd with .net ERDDUG – 11 June 2011
Types of Testing Scenario Testing You pretend to be a user. The app gets tested as a single unit. You’re testing by runningstatic void Main() Can’t test all edge cases. Functional Testing Sub-systems of the app get tested in isolation, e.g. by substituting databases with XML data sources. Ensures that groups of classes interact with each other correctly. When green – sure the subsystem works correctly. When red – easier to reproduce, but still need a debugger to find the exact problem.
Unit Testing Tests each individual class in isolation. Can simulate all edge cases and error conditions Fast – only instantiates the part of the app that’s actually needed for the test When green – know the class is OK in isolation, but haven’t tested interaction with others classes. (Functional test) When red – know we can reproduce the error easily.
What makes code hard to test? Real issues ,[object Object]
Singletons
Mixing new with logic
Work in constructor (static)
Global state

Contenu connexe

En vedette

Statistical Thinking, Systems Thought and Mental Models
Statistical Thinking, Systems Thought and Mental ModelsStatistical Thinking, Systems Thought and Mental Models
Statistical Thinking, Systems Thought and Mental Models
Vinay Kulkarni
 
Portfolio Jur C
Portfolio Jur CPortfolio Jur C
Portfolio Jur C
jurrie68
 
星期八
星期八星期八
星期八
darkhe
 
Letters Of Recommendation
Letters Of RecommendationLetters Of Recommendation
Letters Of Recommendation
russe115
 
UILayout plug-in for APEX
UILayout plug-in for APEXUILayout plug-in for APEX
UILayout plug-in for APEX
Tobias Arnhold
 

En vedette (15)

Financing the World's Forests: integrating markets and stakeholders
Financing the World's Forests: integrating markets and stakeholdersFinancing the World's Forests: integrating markets and stakeholders
Financing the World's Forests: integrating markets and stakeholders
 
Statistical Thinking, Systems Thought and Mental Models
Statistical Thinking, Systems Thought and Mental ModelsStatistical Thinking, Systems Thought and Mental Models
Statistical Thinking, Systems Thought and Mental Models
 
Portfolio Jur C
Portfolio Jur CPortfolio Jur C
Portfolio Jur C
 
Financing the World's Forests: integrating markets and stakeholders
Financing the World's Forests: integrating markets and stakeholdersFinancing the World's Forests: integrating markets and stakeholders
Financing the World's Forests: integrating markets and stakeholders
 
星期八
星期八星期八
星期八
 
Marcas I Marks
Marcas I MarksMarcas I Marks
Marcas I Marks
 
Letters Of Recommendation
Letters Of RecommendationLetters Of Recommendation
Letters Of Recommendation
 
Financing the World's Forests: integrating markets and stakeholders
Financing the World's Forests: integrating markets and stakeholdersFinancing the World's Forests: integrating markets and stakeholders
Financing the World's Forests: integrating markets and stakeholders
 
Trabajo de mendel
Trabajo de mendelTrabajo de mendel
Trabajo de mendel
 
UILayout plug-in for APEX
UILayout plug-in for APEXUILayout plug-in for APEX
UILayout plug-in for APEX
 
Abecedario maluco
Abecedario maluco Abecedario maluco
Abecedario maluco
 
Web Design I Mock-up
Web Design I Mock-upWeb Design I Mock-up
Web Design I Mock-up
 
APEX navigation concepts
APEX navigation conceptsAPEX navigation concepts
APEX navigation concepts
 
Kelly Services We Do That
Kelly Services   We Do ThatKelly Services   We Do That
Kelly Services We Do That
 
APEX Dashboard Competition - Winners
APEX Dashboard Competition - WinnersAPEX Dashboard Competition - Winners
APEX Dashboard Competition - Winners
 

Similaire à Unit testing

Testing and TDD - KoJUG
Testing and TDD - KoJUGTesting and TDD - KoJUG
Testing and TDD - KoJUG
lburdz
 
Break through e2e-testing
Break through e2e-testingBreak through e2e-testing
Break through e2e-testing
tameemahmed5
 

Similaire à Unit testing (20)

Testing and TDD - KoJUG
Testing and TDD - KoJUGTesting and TDD - KoJUG
Testing and TDD - KoJUG
 
Implementing TDD in for .net Core applications
Implementing TDD in for .net Core applicationsImplementing TDD in for .net Core applications
Implementing TDD in for .net Core applications
 
Unit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsUnit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile Apps
 
Nguyenvandungb seminar
Nguyenvandungb seminarNguyenvandungb seminar
Nguyenvandungb seminar
 
Break through e2e-testing
Break through e2e-testingBreak through e2e-testing
Break through e2e-testing
 
Unit testing, principles
Unit testing, principlesUnit testing, principles
Unit testing, principles
 
A lab around the principles and practices for writing maintainable code
A lab around the principles and practices for writing maintainable codeA lab around the principles and practices for writing maintainable code
A lab around the principles and practices for writing maintainable code
 
Headless fragments in Android
Headless fragments in AndroidHeadless fragments in Android
Headless fragments in Android
 
Unit Testing vs Integration Testing
Unit Testing vs Integration TestingUnit Testing vs Integration Testing
Unit Testing vs Integration Testing
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java Progamming Paradigms, OOPS Concept, Introduction to Java, Structure of J...
Java Progamming Paradigms, OOPS Concept, Introduction to Java, Structure of J...Java Progamming Paradigms, OOPS Concept, Introduction to Java, Structure of J...
Java Progamming Paradigms, OOPS Concept, Introduction to Java, Structure of J...
 
Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1
 
Cs6502 ooad-cse-vst-au-unit-v dce
Cs6502 ooad-cse-vst-au-unit-v dceCs6502 ooad-cse-vst-au-unit-v dce
Cs6502 ooad-cse-vst-au-unit-v dce
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
Java_Interview Qns
Java_Interview QnsJava_Interview Qns
Java_Interview Qns
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.
 
Practical unit testing tips
Practical unit testing tipsPractical unit testing tips
Practical unit testing tips
 
M.c.a. (sem iv)- java programming
M.c.a. (sem   iv)- java programmingM.c.a. (sem   iv)- java programming
M.c.a. (sem iv)- java programming
 
Selenium Design Patterns
Selenium Design PatternsSelenium Design Patterns
Selenium Design Patterns
 

Dernier

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

Dernier (20)

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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
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
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
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
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Unit testing

  • 1. Unit testing,mocking &tdd with .net ERDDUG – 11 June 2011
  • 2. Types of Testing Scenario Testing You pretend to be a user. The app gets tested as a single unit. You’re testing by runningstatic void Main() Can’t test all edge cases. Functional Testing Sub-systems of the app get tested in isolation, e.g. by substituting databases with XML data sources. Ensures that groups of classes interact with each other correctly. When green – sure the subsystem works correctly. When red – easier to reproduce, but still need a debugger to find the exact problem.
  • 3. Unit Testing Tests each individual class in isolation. Can simulate all edge cases and error conditions Fast – only instantiates the part of the app that’s actually needed for the test When green – know the class is OK in isolation, but haven’t tested interaction with others classes. (Functional test) When red – know we can reproduce the error easily.
  • 4.
  • 11.
  • 13.
  • 14. Unit Testing Classes Other Class File System CPU Intensive Seam Other Class Other Class Class Under Test Test Driver Other Class Destructive operation Other Class Other Class Other Servers Object Lifetime and Calling Object Instantiated Object Passed In Global Object
  • 15. Unit Testing Classes Seam (Polymorphism) Other Class Friendly Class Under Test Test Driver Other Class Friendly Other Class Object Lifetime and Calling Friendly Object Instantiated Object Passed In Global Object
  • 16. Unit Testing Classes Seam Dependency Injection Friendly Class Under Test Test Driver Friendly Friendly Object Lifetime and Calling Object Instantiated Object Passed In Global Object