SlideShare una empresa de Scribd logo
1 de 15
Unit Tests are Overrated
Lars-Erik Kindblad
Senior Consultant
Twitter: @kindblad
Unit Testing Misconceptions
1. Unit tests can talk to a database, web service etc.
 Not true: That’s integration tests. A unit test tests a class or method in isolation using
stubs or mocks.
 When people say that unit testing is great they might actually mean integration testing
2. Unit tests ensure that a system works 100%
 Not true: A unit test is not an end-to-end test. It only verifies that the class is working in
isolation, it does not verify that it works and integrates with other classes
3. Unit tests allow for safe refactoring
 Not true: Unit tests are too detailed tests. Small refactoring such as splitting a class in two
forces the unit tests to be changed
4. Unit tests improve the code quality
 Not true: Unit tests don’t automatically improve code quality. There are a lot of bad unit
tested code
5. Unit tests reduce the technical debt
 Not true: Very hard to write good unit tests. Big chance that the technical debt increases
Unit Testing Misconceptions
6. 100% unit test coverage means the system is bug free
 Not true: Code coverage only tells us what was executed by our unit tests, not if it was
executed correctly
 int Foo(int a, int b) { return a / b; }
would need more than one test to be verified 100% but one test is enough to get 100%
code coverage
7. Unit testing can replace the QA resources
Not true:
 Developers are really bad at finding bugs
 Unit tests can have bugs
 The requirements could have been misunderstood and implemented wrongly
8. Unit tests are the documentation
 Not true: Most developer trust their code more than their unit tests. The code itself should
be self documenting
A Better Way – Use Case Testing
Integration tests that focuses on the use cases
Business Layer
Infrastructure Layer (DAL)
Presentation/
Services Layer
Endpoints
Database Web Service
Filesystem SMTP Service Bus
Class Class
Class
Class
Use Case Tests Assert on:
 Result from the presentation/services
layer
 Endpoints result or that the endpoints
have received the messages
Advantage:
 Tests at a higher level than unit tests
 Safe and fast to refactor
 Only have to update the tests when the
functionality changes
 Verifies the quality from top to
bottom, from the start of the use case
to the end
 Can write the tests based on the QA
test cases
1. Challenge – Testing the Presentation Layer
A lot of changes happens all the time – the tests must be updated
continually
A lot of infrastructure setup and concerns makes it hard to test
Solution
Add a Use Case Layer for delivery mechanism indepent use cases
Advantage:
 No dependencies to ASP.NET, WPF
or WP.
 100% testable through DTO’s
 Most critical functionality are verified
Disadvantage:
 The presentation layer is not verified
 The Use Cases Layer and the layers below are
most critical, a serious error can corrupt the
system
Use Cases Layer
Business Layer
Infrastructure Layer
Presentation Layer
Use Case Tests
Data Transfer Objects
Endpoints
2. Challenge – Test Data & Verification
 Data at the endpoints changes constantly
 Breaks the tests
 Impossible to verify the result
Solution 1/2
Solution 2/2
3. Challenge - Non-Controllable Endpoints
Don’t have access to delete and create testdata at the endpoint
Not possible to verify the result at the endpoint
Cannot verify our use case
Business Logic
Use Cases
Tests
Database
SMTP
Server
Solution
Create a copy of the existing endpoint to use it for testing only
Replace the endpoint with a fake endpoint using dependency inversion
& the Onion Architecture to verify the flow of the use case
- ICustomerRepository
- IEmailSender
- FakeEmailSender
- CustomerRepository
- EmailSender
Fake E-Mail Endpoint Implementation
4. Challenge - Slow Tests
Takes too long to run
Solution:
Better to have slow tests that verify the quality 100% than fast tests that do
not
Replace the endpoints with fake in-memory endpoints
Test Strategy
The test strategy for my current project:
1. Write use case tests to verify the end-to-end quality
 Important to test both the success- and the fail scenarios
2. Write unit tests or integration tests to test complex logic and algorithms
such as calculations
3. When using fake endpoints for testing: Write integration tests to verify
that the basics of the non-fake implementations work.
Every project is different = Define your own test strategy!
The information contained in this presentation is proprietary.
© 2012 Capgemini. All rights reserved.
www.capgemini.com
About Capgemini
With more than 120,000 people in 40 countries, Capgemini is one
of the world's foremost providers of consulting, technology and
outsourcing services. The Group reported 2011 global revenues
of EUR 9.7 billion.
Together with its clients, Capgemini creates and delivers
business and technology solutions that fit their needs and drive
the results they want. A deeply multicultural organization,
Capgemini has developed its own way of working, the
Collaborative Business ExperienceTM, and draws on Rightshore ®,
its worldwide delivery model.
Rightshore® is a trademark belonging to Capgemini

Más contenido relacionado

La actualidad más candente

Finding Patterns in the Clouds - Cloud Design Patterns
Finding Patterns in the Clouds - Cloud Design PatternsFinding Patterns in the Clouds - Cloud Design Patterns
Finding Patterns in the Clouds - Cloud Design PatternsSteven Smith
 
Symantec I3 - Inquire & Cluster
Symantec I3 - Inquire & Cluster Symantec I3 - Inquire & Cluster
Symantec I3 - Inquire & Cluster sebastian.guerrero
 
Automation Framework 042009 V2
Automation Framework   042009  V2Automation Framework   042009  V2
Automation Framework 042009 V2guestb66d91
 
Somesh_Tessolve_updated _resume
Somesh_Tessolve_updated _resumeSomesh_Tessolve_updated _resume
Somesh_Tessolve_updated _resumeSomesh Mishra
 
Flex and PHP For the Flash Folks
Flex and PHP For the Flash FolksFlex and PHP For the Flash Folks
Flex and PHP For the Flash Folks10n Software, LLC
 
Code quality
Code qualityCode quality
Code qualityProvectus
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftTalentica Software
 
Quality metrics and angular js applications
Quality metrics and angular js applicationsQuality metrics and angular js applications
Quality metrics and angular js applicationsnadeembtech
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoringkim.mens
 
Code coverage & tools
Code coverage & toolsCode coverage & tools
Code coverage & toolsRajesh Kumar
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3aminmesbahi
 
Loopt unit test experiences
Loopt unit test experiencesLoopt unit test experiences
Loopt unit test experiencesHeine Frifeldt
 
amazon-cognito-auth-in-minutes
amazon-cognito-auth-in-minutesamazon-cognito-auth-in-minutes
amazon-cognito-auth-in-minutesVladimir Budilov
 
VA Code Completion
VA Code CompletionVA Code Completion
VA Code CompletionESUG
 
Java code coverage with JCov. Implementation details and use cases.
Java code coverage with JCov. Implementation details and use cases.Java code coverage with JCov. Implementation details and use cases.
Java code coverage with JCov. Implementation details and use cases.Alexandre (Shura) Iline
 
Hybrid Automation Framework Development introduction
Hybrid Automation Framework Development introductionHybrid Automation Framework Development introduction
Hybrid Automation Framework Development introductionGanuka Yashantha
 

La actualidad más candente (20)

Finding Patterns in the Clouds - Cloud Design Patterns
Finding Patterns in the Clouds - Cloud Design PatternsFinding Patterns in the Clouds - Cloud Design Patterns
Finding Patterns in the Clouds - Cloud Design Patterns
 
Code coverage
Code coverageCode coverage
Code coverage
 
Symantec I3 - Inquire & Cluster
Symantec I3 - Inquire & Cluster Symantec I3 - Inquire & Cluster
Symantec I3 - Inquire & Cluster
 
Automation Framework 042009 V2
Automation Framework   042009  V2Automation Framework   042009  V2
Automation Framework 042009 V2
 
Somesh_Tessolve_updated _resume
Somesh_Tessolve_updated _resumeSomesh_Tessolve_updated _resume
Somesh_Tessolve_updated _resume
 
Flex and PHP For the Flash Folks
Flex and PHP For the Flash FolksFlex and PHP For the Flash Folks
Flex and PHP For the Flash Folks
 
Code quality
Code qualityCode quality
Code quality
 
Using Automation to Improve Software Services
Using Automation to Improve Software ServicesUsing Automation to Improve Software Services
Using Automation to Improve Software Services
 
Apex code (Salesforce)
Apex code (Salesforce)Apex code (Salesforce)
Apex code (Salesforce)
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
 
Quality metrics and angular js applications
Quality metrics and angular js applicationsQuality metrics and angular js applications
Quality metrics and angular js applications
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Code coverage & tools
Code coverage & toolsCode coverage & tools
Code coverage & tools
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3
 
Loopt unit test experiences
Loopt unit test experiencesLoopt unit test experiences
Loopt unit test experiences
 
amazon-cognito-auth-in-minutes
amazon-cognito-auth-in-minutesamazon-cognito-auth-in-minutes
amazon-cognito-auth-in-minutes
 
VA Code Completion
VA Code CompletionVA Code Completion
VA Code Completion
 
Java code coverage with JCov. Implementation details and use cases.
Java code coverage with JCov. Implementation details and use cases.Java code coverage with JCov. Implementation details and use cases.
Java code coverage with JCov. Implementation details and use cases.
 
Hybrid Automation Framework Development introduction
Hybrid Automation Framework Development introductionHybrid Automation Framework Development introduction
Hybrid Automation Framework Development introduction
 
PRG 420 Entire Course NEW
PRG 420 Entire Course NEWPRG 420 Entire Course NEW
PRG 420 Entire Course NEW
 

Destacado

Responsive Design - Quick & Dirty
Responsive Design - Quick & DirtyResponsive Design - Quick & Dirty
Responsive Design - Quick & DirtyArno Selhorst
 
Webinar: Responsive Design
Webinar: Responsive DesignWebinar: Responsive Design
Webinar: Responsive Designkuehlhaus AG
 
Introduction to FluentData - The Micro ORM
Introduction to FluentData - The Micro ORMIntroduction to FluentData - The Micro ORM
Introduction to FluentData - The Micro ORMLars-Erik Kindblad
 
Avoid code duplication! Principles & Patterns
Avoid code duplication! Principles & PatternsAvoid code duplication! Principles & Patterns
Avoid code duplication! Principles & PatternsLars-Erik Kindblad
 
Application Architecture by Lars-Erik Kindblad, Capgemini
Application Architecture by Lars-Erik Kindblad, CapgeminiApplication Architecture by Lars-Erik Kindblad, Capgemini
Application Architecture by Lars-Erik Kindblad, CapgeminiLars-Erik Kindblad
 
Dependency Injection vs Service Locator - Best Practice
Dependency Injection vs Service Locator - Best PracticeDependency Injection vs Service Locator - Best Practice
Dependency Injection vs Service Locator - Best PracticeLars-Erik Kindblad
 
How to build more reliable, robust and scalable distributed systems
How to build more reliable, robust and scalable distributed systemsHow to build more reliable, robust and scalable distributed systems
How to build more reliable, robust and scalable distributed systemsLars-Erik Kindblad
 
Application Architecture April 2014
Application Architecture April 2014Application Architecture April 2014
Application Architecture April 2014Lars-Erik Kindblad
 
Anforderungsanalyse und UML Grundlagen
Anforderungsanalyse und UML GrundlagenAnforderungsanalyse und UML Grundlagen
Anforderungsanalyse und UML GrundlagenChristian Baranowski
 
Domain Driven Design und Nosql
Domain Driven Design und Nosql Domain Driven Design und Nosql
Domain Driven Design und Nosql ArangoDB Database
 
Mobile Patterns - Wie Apps und Co. digitale Interfaces revolutionieren
Mobile Patterns - Wie Apps und Co. digitale Interfaces revolutionierenMobile Patterns - Wie Apps und Co. digitale Interfaces revolutionieren
Mobile Patterns - Wie Apps und Co. digitale Interfaces revolutionierenMarkus Greve
 
The Single Responsibility Principle
The Single Responsibility PrincipleThe Single Responsibility Principle
The Single Responsibility PrincipleLars-Erik Kindblad
 
Publish & Subscribe to events using an Event Aggregator
Publish & Subscribe to events using an Event AggregatorPublish & Subscribe to events using an Event Aggregator
Publish & Subscribe to events using an Event AggregatorLars-Erik Kindblad
 
Inversion of Control - Introduction and Best Practice
Inversion of Control - Introduction and Best PracticeInversion of Control - Introduction and Best Practice
Inversion of Control - Introduction and Best PracticeLars-Erik Kindblad
 
Domain-driven design - eine Einführung
Domain-driven design - eine EinführungDomain-driven design - eine Einführung
Domain-driven design - eine Einführungdie.agilen GmbH
 
Roadmap von Microsoft UI Technologien und Windows 8
Roadmap von Microsoft UI Technologien und Windows 8Roadmap von Microsoft UI Technologien und Windows 8
Roadmap von Microsoft UI Technologien und Windows 8chmoser79
 

Destacado (20)

Ready or not: No UI vom Verschwinden des Graphical User Interfaces
Ready or not: No UI vom Verschwinden des Graphical User InterfacesReady or not: No UI vom Verschwinden des Graphical User Interfaces
Ready or not: No UI vom Verschwinden des Graphical User Interfaces
 
Responsive Design - Quick & Dirty
Responsive Design - Quick & DirtyResponsive Design - Quick & Dirty
Responsive Design - Quick & Dirty
 
Webinar: Responsive Design
Webinar: Responsive DesignWebinar: Responsive Design
Webinar: Responsive Design
 
Introduction to FluentData - The Micro ORM
Introduction to FluentData - The Micro ORMIntroduction to FluentData - The Micro ORM
Introduction to FluentData - The Micro ORM
 
Avoid code duplication! Principles & Patterns
Avoid code duplication! Principles & PatternsAvoid code duplication! Principles & Patterns
Avoid code duplication! Principles & Patterns
 
Application Architecture by Lars-Erik Kindblad, Capgemini
Application Architecture by Lars-Erik Kindblad, CapgeminiApplication Architecture by Lars-Erik Kindblad, Capgemini
Application Architecture by Lars-Erik Kindblad, Capgemini
 
Dependency Injection vs Service Locator - Best Practice
Dependency Injection vs Service Locator - Best PracticeDependency Injection vs Service Locator - Best Practice
Dependency Injection vs Service Locator - Best Practice
 
Systementwurf mit UML
Systementwurf mit UMLSystementwurf mit UML
Systementwurf mit UML
 
How to build more reliable, robust and scalable distributed systems
How to build more reliable, robust and scalable distributed systemsHow to build more reliable, robust and scalable distributed systems
How to build more reliable, robust and scalable distributed systems
 
The Fluent Interface Pattern
The Fluent Interface PatternThe Fluent Interface Pattern
The Fluent Interface Pattern
 
Application Architecture April 2014
Application Architecture April 2014Application Architecture April 2014
Application Architecture April 2014
 
Anforderungsanalyse und UML Grundlagen
Anforderungsanalyse und UML GrundlagenAnforderungsanalyse und UML Grundlagen
Anforderungsanalyse und UML Grundlagen
 
Domain Driven Design und Nosql
Domain Driven Design und Nosql Domain Driven Design und Nosql
Domain Driven Design und Nosql
 
Mobile Patterns - Wie Apps und Co. digitale Interfaces revolutionieren
Mobile Patterns - Wie Apps und Co. digitale Interfaces revolutionierenMobile Patterns - Wie Apps und Co. digitale Interfaces revolutionieren
Mobile Patterns - Wie Apps und Co. digitale Interfaces revolutionieren
 
The Single Responsibility Principle
The Single Responsibility PrincipleThe Single Responsibility Principle
The Single Responsibility Principle
 
Publish & Subscribe to events using an Event Aggregator
Publish & Subscribe to events using an Event AggregatorPublish & Subscribe to events using an Event Aggregator
Publish & Subscribe to events using an Event Aggregator
 
Data Access - Best Practice
Data Access - Best PracticeData Access - Best Practice
Data Access - Best Practice
 
Inversion of Control - Introduction and Best Practice
Inversion of Control - Introduction and Best PracticeInversion of Control - Introduction and Best Practice
Inversion of Control - Introduction and Best Practice
 
Domain-driven design - eine Einführung
Domain-driven design - eine EinführungDomain-driven design - eine Einführung
Domain-driven design - eine Einführung
 
Roadmap von Microsoft UI Technologien und Windows 8
Roadmap von Microsoft UI Technologien und Windows 8Roadmap von Microsoft UI Technologien und Windows 8
Roadmap von Microsoft UI Technologien und Windows 8
 

Similar a Unit Tests are Overrated (NDCOslo 2013)

Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingCameron Presley
 
Generating Test Cases
Generating Test CasesGenerating Test Cases
Generating Test CasesVivekRajawat9
 
Software testing for biginners
Software testing for biginnersSoftware testing for biginners
Software testing for biginnersSriman Eshwar
 
Software testing introduction
Software testing introductionSoftware testing introduction
Software testing introductionSriman Eshwar
 
Automation testing
Automation testingAutomation testing
Automation testingTomy Rhymond
 
Testing 3: Types Of Tests That May Be Required
Testing 3: Types Of Tests That May Be RequiredTesting 3: Types Of Tests That May Be Required
Testing 3: Types Of Tests That May Be RequiredArleneAndrews2
 
Testing Software Solutions
Testing Software SolutionsTesting Software Solutions
Testing Software Solutionsgavhays
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...AgileNetwork
 
testing.pdf
testing.pdftesting.pdf
testing.pdfkumari36
 
Mantra Tech Overview.pdf
Mantra Tech Overview.pdfMantra Tech Overview.pdf
Mantra Tech Overview.pdfRubenBert
 
Need To Automate Test And Integration Beyond Current Limits?
Need To Automate Test And Integration Beyond Current Limits?Need To Automate Test And Integration Beyond Current Limits?
Need To Automate Test And Integration Beyond Current Limits?Ghodhbane Mohamed Amine
 
Introduction of unit test to management
Introduction of unit test to managementIntroduction of unit test to management
Introduction of unit test to managementweili_at_slideshare
 
Automated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra SolutionsAutomated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra SolutionsQuontra Solutions
 

Similar a Unit Tests are Overrated (NDCOslo 2013) (20)

Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To Testing
 
Generating Test Cases
Generating Test CasesGenerating Test Cases
Generating Test Cases
 
Software testing for biginners
Software testing for biginnersSoftware testing for biginners
Software testing for biginners
 
Software testing introduction
Software testing introductionSoftware testing introduction
Software testing introduction
 
Testing
TestingTesting
Testing
 
Automation testing
Automation testingAutomation testing
Automation testing
 
Testing 3: Types Of Tests That May Be Required
Testing 3: Types Of Tests That May Be RequiredTesting 3: Types Of Tests That May Be Required
Testing 3: Types Of Tests That May Be Required
 
Testing Software Solutions
Testing Software SolutionsTesting Software Solutions
Testing Software Solutions
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
 
testing.pdf
testing.pdftesting.pdf
testing.pdf
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Mantra Tech Overview.pdf
Mantra Tech Overview.pdfMantra Tech Overview.pdf
Mantra Tech Overview.pdf
 
QA.pdf
QA.pdfQA.pdf
QA.pdf
 
Software testing methods
Software testing methodsSoftware testing methods
Software testing methods
 
Need To Automate Test And Integration Beyond Current Limits?
Need To Automate Test And Integration Beyond Current Limits?Need To Automate Test And Integration Beyond Current Limits?
Need To Automate Test And Integration Beyond Current Limits?
 
Introduction of unit test to management
Introduction of unit test to managementIntroduction of unit test to management
Introduction of unit test to management
 
Automated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra SolutionsAutomated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra Solutions
 

Último

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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, ...apidays
 
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 Takeoffsammart93
 
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...DianaGray10
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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...apidays
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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 WoodJuan lago vázquez
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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 CVKhem
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim 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 businesspanagenda
 

Último (20)

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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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, ...
 
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
 
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...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
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...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 

Unit Tests are Overrated (NDCOslo 2013)

  • 1. Unit Tests are Overrated Lars-Erik Kindblad Senior Consultant Twitter: @kindblad
  • 2. Unit Testing Misconceptions 1. Unit tests can talk to a database, web service etc.  Not true: That’s integration tests. A unit test tests a class or method in isolation using stubs or mocks.  When people say that unit testing is great they might actually mean integration testing 2. Unit tests ensure that a system works 100%  Not true: A unit test is not an end-to-end test. It only verifies that the class is working in isolation, it does not verify that it works and integrates with other classes 3. Unit tests allow for safe refactoring  Not true: Unit tests are too detailed tests. Small refactoring such as splitting a class in two forces the unit tests to be changed 4. Unit tests improve the code quality  Not true: Unit tests don’t automatically improve code quality. There are a lot of bad unit tested code 5. Unit tests reduce the technical debt  Not true: Very hard to write good unit tests. Big chance that the technical debt increases
  • 3. Unit Testing Misconceptions 6. 100% unit test coverage means the system is bug free  Not true: Code coverage only tells us what was executed by our unit tests, not if it was executed correctly  int Foo(int a, int b) { return a / b; } would need more than one test to be verified 100% but one test is enough to get 100% code coverage 7. Unit testing can replace the QA resources Not true:  Developers are really bad at finding bugs  Unit tests can have bugs  The requirements could have been misunderstood and implemented wrongly 8. Unit tests are the documentation  Not true: Most developer trust their code more than their unit tests. The code itself should be self documenting
  • 4. A Better Way – Use Case Testing Integration tests that focuses on the use cases Business Layer Infrastructure Layer (DAL) Presentation/ Services Layer Endpoints Database Web Service Filesystem SMTP Service Bus Class Class Class Class Use Case Tests Assert on:  Result from the presentation/services layer  Endpoints result or that the endpoints have received the messages Advantage:  Tests at a higher level than unit tests  Safe and fast to refactor  Only have to update the tests when the functionality changes  Verifies the quality from top to bottom, from the start of the use case to the end  Can write the tests based on the QA test cases
  • 5. 1. Challenge – Testing the Presentation Layer A lot of changes happens all the time – the tests must be updated continually A lot of infrastructure setup and concerns makes it hard to test
  • 6. Solution Add a Use Case Layer for delivery mechanism indepent use cases Advantage:  No dependencies to ASP.NET, WPF or WP.  100% testable through DTO’s  Most critical functionality are verified Disadvantage:  The presentation layer is not verified  The Use Cases Layer and the layers below are most critical, a serious error can corrupt the system Use Cases Layer Business Layer Infrastructure Layer Presentation Layer Use Case Tests Data Transfer Objects Endpoints
  • 7. 2. Challenge – Test Data & Verification  Data at the endpoints changes constantly  Breaks the tests  Impossible to verify the result
  • 10. 3. Challenge - Non-Controllable Endpoints Don’t have access to delete and create testdata at the endpoint Not possible to verify the result at the endpoint Cannot verify our use case
  • 11. Business Logic Use Cases Tests Database SMTP Server Solution Create a copy of the existing endpoint to use it for testing only Replace the endpoint with a fake endpoint using dependency inversion & the Onion Architecture to verify the flow of the use case - ICustomerRepository - IEmailSender - FakeEmailSender - CustomerRepository - EmailSender
  • 12. Fake E-Mail Endpoint Implementation
  • 13. 4. Challenge - Slow Tests Takes too long to run Solution: Better to have slow tests that verify the quality 100% than fast tests that do not Replace the endpoints with fake in-memory endpoints
  • 14. Test Strategy The test strategy for my current project: 1. Write use case tests to verify the end-to-end quality  Important to test both the success- and the fail scenarios 2. Write unit tests or integration tests to test complex logic and algorithms such as calculations 3. When using fake endpoints for testing: Write integration tests to verify that the basics of the non-fake implementations work. Every project is different = Define your own test strategy!
  • 15. The information contained in this presentation is proprietary. © 2012 Capgemini. All rights reserved. www.capgemini.com About Capgemini With more than 120,000 people in 40 countries, Capgemini is one of the world's foremost providers of consulting, technology and outsourcing services. The Group reported 2011 global revenues of EUR 9.7 billion. Together with its clients, Capgemini creates and delivers business and technology solutions that fit their needs and drive the results they want. A deeply multicultural organization, Capgemini has developed its own way of working, the Collaborative Business ExperienceTM, and draws on Rightshore ®, its worldwide delivery model. Rightshore® is a trademark belonging to Capgemini