SlideShare a Scribd company logo
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

More Related Content

Viewers also liked

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
E Rivilla
 
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 Cjurrie68
 
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
E Rivilla
 
星期八
星期八星期八
星期八darkhe
 
Marcas I Marks
Marcas I MarksMarcas I Marks
Marcas I Marks
Isobelle
 
Letters Of Recommendation
Letters Of RecommendationLetters Of Recommendation
Letters Of Recommendation
russe115
 
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
E Rivilla
 
Trabajo de mendel
Trabajo de mendelTrabajo de mendel
Trabajo de mendel
manudjs80s
 
UILayout plug-in for APEX
UILayout plug-in for APEXUILayout plug-in for APEX
UILayout plug-in for APEX
Tobias Arnhold
 
Abecedario maluco
Abecedario maluco Abecedario maluco
Abecedario maluco
Luciana Jardim
 
Web Design I Mock-up
Web Design I Mock-upWeb Design I Mock-up
Web Design I Mock-up
Isobelle
 
APEX navigation concepts
APEX navigation conceptsAPEX navigation concepts
APEX navigation concepts
Tobias Arnhold
 
Kelly Services We Do That
Kelly Services   We Do ThatKelly Services   We Do That
Kelly Services We Do That
guestab957f
 
APEX Dashboard Competition - Winners
APEX Dashboard Competition - WinnersAPEX Dashboard Competition - Winners
APEX Dashboard Competition - Winners
Tobias Arnhold
 

Viewers also liked (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
 

Similar to Unit testing

Testing and TDD - KoJUG
Testing and TDD - KoJUGTesting and TDD - KoJUG
Testing and TDD - KoJUG
lburdz
 
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
Ahmad Kazemi
 
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
Marcelo Busico
 
Nguyenvandungb seminar
Nguyenvandungb seminarNguyenvandungb seminar
Nguyenvandungb seminar
dunglinh111
 
Break through e2e-testing
Break through e2e-testingBreak through e2e-testing
Break through e2e-testing
tameemahmed5
 
Unit testing, principles
Unit testing, principlesUnit testing, principles
Unit testing, principles
Renato Primavera
 
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
Dennis Doomen
 
Headless fragments in Android
Headless fragments in AndroidHeadless fragments in Android
Headless fragments in Android
Ali Muzaffar
 
Unit Testing vs Integration Testing
Unit Testing vs Integration TestingUnit Testing vs Integration Testing
Unit Testing vs Integration Testing
Rock Interview
 
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
Gradeup
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
Sujit Majety
 
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...
Sakthi Durai
 
Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1
Sakthi Durai
 
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
tagoreengineering
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
L&T Technology Services Limited
 
Java_Interview Qns
Java_Interview QnsJava_Interview Qns
Java_Interview Qns
ManikandanRamanujam
 
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.
Mohamed Taman
 
Practical unit testing tips
Practical unit testing tipsPractical unit testing tips
Practical unit testing tips
Typemock
 
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
Praveen Chowdary
 
Selenium Design Patterns
Selenium Design PatternsSelenium Design Patterns
Selenium Design Patterns
Liraz Shay
 

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

Recently uploaded

Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
saastr
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
GDSC PJATK
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 

Recently uploaded (20)

Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 

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