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

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked

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
 

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

Recently uploaded

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
[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.pdfhans926745
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
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 organizationRadu Cotescu
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
[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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
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
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 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)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 

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