SlideShare une entreprise Scribd logo
1  sur  68
Making the Unstable Stable
An Introduction to Testing
CAMERON PRESLEY
@PCAMERONPRESLEY
HTTP://BLOG.THESOFTWAREMENTOR.COM
Outline
◦Personal Experience
◦Business Case for Testing
◦Intro to Testing
◦Next Steps
◦Additional Resources
Tale of Three Companies
Company A
Large, privately held EMR company
Hundreds of developers
Very mature codebase
Background
Team consisted of 3 developers, 2 QA
Tool that moved patient info from one hospital to another
Errors could lead to data integrity issues
Experience
Fear of refactoring code (too brittle)
Bugs kept coming back
Firefighting mode
No clear focus
What Did I Learn?
Bug count never decreased
Regressions in functionality
Firefighting all the time
Relied upon QA to find issues for us
Company B
Small publicly held company in the healthcare industry
Medical diagnostic device with custom hardware
Coming into a rewrite of the software
Background
Team consisted of 3 developers, 1 QA
Responsible for calculating test results for given samples
Errors could lead to the doctor making the wrong decision
Experience
Refactored constantly
Heavily unit tested components
Bugs never came back
Clear focus on goals
Lessons Learned
Bug count decreased and able to focus on new features
Confidence that we didn’t break anything (able to change freely)
Was it the team or was it testing?
Company C
Startup in the project management space
Help project manager plan “what-if” scenarios
Working on the initial release of the software
Background
Team consisted of 3 developers, 2 QA
Responsible for all parts of the application
Errors could lead to managers making the wrong decision
Experience
Lots of bugs
Demos would crash
◦ “Pucker factor”
Reactive, not proactive
Experience
Spent time teaching the team how and when to write tests
Product began to stabilize
Fewer bugs were being found
Experience
Shipped a massive feature with zero bugs
Confidence in the product soared
Began to focus on new features
Experience
When I left, there were over 4,000 tests
Entire codebase not covered
◦ Covered major features/functionality
Never regressed
Personal Experience
Testing allows developers to make the changes in a low-risk
fashion
Software becomes easier to change to reflect new requirements
This is pure anecdote, where’s the research?
Business Case for Testing
Background
V1 consisted of 1,000 KLOCs written over the course of 3 years
Functional testing (manual testing) was used to ensure the
product was working correctly
No automated testing was happening
◦ Ad-hoc at best
Experiment
V2 consisted of 200 KLOCs of new code and 150 KLOCs of
changed code
Mandated unit tests on new functionality
Still relied upon functional testing to ensure no regressions
Results
During code reviews, reviewers could reject changes due to
not enough tests
Tests covered 34% of functionality
With manual testing, 85% of functionality was covered
Results
Defect Severity Version 1 Version 2
Severity 1 15.5% 16.8%
Severity 2 49.8% 40.1%
Severity 3 28.7% 18.8%
Severity 4 6.0% 3.4%
21% drop in bugs at a cost of 30% more development time
Customers Increased 10x
Support Costs Increased 3x
Developers’ Perceptions
Spent less time fixing bugs
Writing tests helped with recognizing error conditions
Helped to understand inherited code
Felt more comfortable making changes to code
Testers’ Perception
Code is much higher quality
Harder to find bugs, all the obvious ones are gone
Able to spend more time looking for more complicated errors
Not finding “happy path” bugs
Code Complete
Implementation
Errors
Lack of Domain
Knowledge
Changing
Requirements
Communication
Mishaps
What are the top ways bugs are created?
Code Complete
80% of all bugs come from 20% of the code
80% of maintenance comes from 20% of the code
Code Complete
Time
Introduced
Requirements Architecture Construction System
Test
Post-Release
Requirements 1 3 5-10 10 10-100
Architecture - 1 10 15 25-100
Construction - - 1 10 10-25
Automated Testing Can Provide…
Examples of what the code should do
Built-in documentation
A way to make sure requirements are met
Common language for everyone
The Art of Unit Testing
The Art of Unit Testing
Stage Without Tests With Tests
Implementation 7 14
Integration 7 2
Testing and Bug Fixing
Testing
Fixing
Testing
Fixing
Testing
3
3
3
2
1
3
1
1
1
1
Total 26 23
Bugs Found In Production 71 11
Introduction to Testing
Introducing the Testing Triangle
Introduced by Michael Cohn in
Succeeding with Agile
Breakdown of a test suite
◦ 10% UI
◦ 20% Integration
◦ 70% Unit
Example Test
Parts of a Test (AAA)
Arrange – Get code ready to test
◦ Create dependencies, set properties, call methods, etc…
Act – Call the code that is being tested
◦ Method, non-trivial property, constructor, etc…
Assert – Did we get what we expected?
◦ Throw an exception?, Return an empty list?, Return 42?
Using AAA
Types of Automated Tests
Unit Tests
◦ Does this one piece work as expected?
Integration Tests
◦ Does this one piece work as I’d expect with others?
UI/Functional/End-to-End
◦ When performing this workflow, does the application do what I’d
expect?
Unit Tests
“A unit test is an automated piece of code that invokes a unit
of work being tested, and then checks some assumptions
about a single end result of that unit.”
- Roy Osherove (The Art of Unit Testing 2nd Edition)
Unit Tests
DOES NOT DEPEND UPON EXTERNAL FACTORS!
Typically tests a method or non-trivial property
Super fast to run (100+ per second)
Aren’t likely to change with infrastructure changes
Integration Tests
“Integration testing is testing a unit of work without having
full control over all of it and using one or more real
dependencies, such as time, network, database, threads,
number generators, and so on.”
- Roy Osherove (The Art of Unit Testing 2nd Edition)
Integration Tests
Tests how your code interacts with databases, networks, 3rd party
resources
Moderately fast to run (10+ per second)
Decently robust, but can be hard to verify correct behavior
UI Tests
Tests the application by driving the UI
Primarily used for end-to-end testing
Very slow (takes seconds per test)
Very fragile since UI changes can cause the test to break
UI Tests
Record and play-back
◦Records the interaction between user and application
◦Can be done with QA
Coded
◦Specify UI controls by ID or label to interact with
◦Primarily developer driven
Tools of the Trade
Testing Framework
Absolute minimum for writing tests
Provides a way to mark classes/methods as tests
Allows us to check if result is what we expected
◦ AreEqual, IsTrue, IsFalse, etc…
Testing Framework
Mocking Framework
Unit tests are faster than integration tests
Lot of code involves different classes collaborating together
How do we unit test these classes?
Create test dependencies that we can control
◦ Using interfaces or inheritance
Mocking Framework
Creates a lot of test code
Mocking framework uses reflection to create dependencies
Can be used to check that methods/properties were called or to stub a
response
Examples
◦ NSbustitute, Moq, Mockito
Mocking Framework
Asserting Methods Were Called
Mocking Framework
Stubbing Responses
UI Framework
Provides a mechanism to interact with UI controls
Great to provide end-to-end workflow testing
Examples
◦Test Stack White (Desktop), Selenium (Web), HP Quick Test Pro
Tools of the Trade
Testing Framework
◦ Allows us to write tests
Mocking Framework
◦ Allows us to switch out real dependencies for fake ones
UI Framework
◦ Allows us to interact with the UI components
Next Steps
Learning How to Write Tests
Sample Exercises
◦Fizz Buzz
◦String Calculator
◦Bowling Game
◦Mars Rover
Next Steps
Identify Problem Areas
Find places in your codebase that have few dependencies
◦ Easier to test and will help build confidence
Find places in your codebase that generates bugs
◦ Remember 80% of issues come from 20% of the code
◦ Might need to refactor code to make it testable
Don’t know the areas? Ask QA
Next Steps
Low Impact Testing
Don’t have to immediately write tests around everything
Start by adding tests on code that you change going forward
Just focus on bug fixes
◦ Write a test that fails because the bug exists
◦ Test should pass once the bug is fixed
Next Steps
Convincing Your Boss
Goal is to move applications to production
Remember, bugs are more expensive the later they’re found
◦ 25x more expensive if not caught before production
Every time QA finds a bug, there’s going to be churn
Puts more pressure on QA and the developers
If You’re a Manager…
Identify those on your team that know how to write tests
◦ Have those developers distribute their knowledge to others
Provide training on how to write tests
◦ Pluralsight has some great resources (free 12 month access for all MSDN holders)
◦ The Art of Unit Testing (2nd Edition) by Roy Osherove
Incorporate slack time to give developers time to learn
Remember!
Goal is to decrease time to production, not 100% code coverage
Not all applications need tests
Not every single line of code needs coverage
◦ 80% of issues come from 20% of the code
Be pragmatic, not dogmatic with testing
Want to Learn More?
10,000 foot view on testing
◦ Starting to Unit Test: Not as Hard as You Think (e-book) by Erik Dietrich
In-Depth Look at Testing
◦ The Art of Unit Testing (2nd Edition) by Roy Osherove
Testing Legacy Code
◦ Working Effectively With Legacy Code by Michael Feathers
◦ Refactoring by Martin Fowler
Additional Resources
Books
◦ Code Complete (2nd Edition) by Steve McConnell
Articles
◦ On the Effectiveness of Unit Testing at Microsoft
Presentations
◦ Unit Testing Makes Me Faster by Jeremy Clark
Videos
◦ Introduction to .NET Testing with NUnit by Jason Roberts
Thanks!
Email: Cameron@TheSoftwareMentor.com
Twitter: @PCameronPresley
Blog: http://blog.TheSoftwareMentor.com

Contenu connexe

Tendances

Common mistakes in software testing and how to overcome?
Common mistakes in software testing and how to overcome?Common mistakes in software testing and how to overcome?
Common mistakes in software testing and how to overcome?MD ISLAM
 
How to be proud when you are done
How to be proud when you are doneHow to be proud when you are done
How to be proud when you are doneAleksey Solntsev
 
Extreme & pair programming Slides ppt
Extreme & pair programming Slides pptExtreme & pair programming Slides ppt
Extreme & pair programming Slides pptMr SMAK
 
Re-thinking Test Automation and Test Process Modelling (in pictures)
Re-thinking Test Automation and Test Process Modelling (in pictures)Re-thinking Test Automation and Test Process Modelling (in pictures)
Re-thinking Test Automation and Test Process Modelling (in pictures)Alan Richardson
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flexmichael.labriola
 
Test driven development
Test driven developmentTest driven development
Test driven developmentNascenia IT
 
Unit Test Lab - Why Write Unit Tests?
Unit Test Lab - Why Write Unit Tests?Unit Test Lab - Why Write Unit Tests?
Unit Test Lab - Why Write Unit Tests?Danny van Kasteel
 
Introduction to Test Driven Development
Introduction to Test Driven DevelopmentIntroduction to Test Driven Development
Introduction to Test Driven DevelopmentMichael Denomy
 
Teaching Kids Programming
Teaching Kids ProgrammingTeaching Kids Programming
Teaching Kids ProgrammingLynn Langit
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentZendCon
 
@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPECWojciech Bulaty
 
Test Driven Development (TDD) & Continuous Integration (CI)
Test Driven Development (TDD) & Continuous Integration (CI)Test Driven Development (TDD) & Continuous Integration (CI)
Test Driven Development (TDD) & Continuous Integration (CI)Fatkul Amri
 
Four Stages of Automated Testing by Bradley Temple
Four Stages of Automated Testing by Bradley TempleFour Stages of Automated Testing by Bradley Temple
Four Stages of Automated Testing by Bradley TempleQA or the Highway
 
Dev Ops Essentials Course
Dev Ops Essentials CourseDev Ops Essentials Course
Dev Ops Essentials CourseUse DevOps
 

Tendances (20)

Tdd
TddTdd
Tdd
 
Code review
Code reviewCode review
Code review
 
Common mistakes in software testing and how to overcome?
Common mistakes in software testing and how to overcome?Common mistakes in software testing and how to overcome?
Common mistakes in software testing and how to overcome?
 
XP Injection
XP InjectionXP Injection
XP Injection
 
How to be proud when you are done
How to be proud when you are doneHow to be proud when you are done
How to be proud when you are done
 
Extreme & pair programming Slides ppt
Extreme & pair programming Slides pptExtreme & pair programming Slides ppt
Extreme & pair programming Slides ppt
 
Re-thinking Test Automation and Test Process Modelling (in pictures)
Re-thinking Test Automation and Test Process Modelling (in pictures)Re-thinking Test Automation and Test Process Modelling (in pictures)
Re-thinking Test Automation and Test Process Modelling (in pictures)
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Unit Test Lab - Why Write Unit Tests?
Unit Test Lab - Why Write Unit Tests?Unit Test Lab - Why Write Unit Tests?
Unit Test Lab - Why Write Unit Tests?
 
Introduction to Test Driven Development
Introduction to Test Driven DevelopmentIntroduction to Test Driven Development
Introduction to Test Driven Development
 
Teaching Kids Programming
Teaching Kids ProgrammingTeaching Kids Programming
Teaching Kids Programming
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC
 
Test Driven Development (TDD) & Continuous Integration (CI)
Test Driven Development (TDD) & Continuous Integration (CI)Test Driven Development (TDD) & Continuous Integration (CI)
Test Driven Development (TDD) & Continuous Integration (CI)
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Four Stages of Automated Testing by Bradley Temple
Four Stages of Automated Testing by Bradley TempleFour Stages of Automated Testing by Bradley Temple
Four Stages of Automated Testing by Bradley Temple
 
Put to the Test
Put to the TestPut to the Test
Put to the Test
 
Dev Ops Essentials Course
Dev Ops Essentials CourseDev Ops Essentials Course
Dev Ops Essentials Course
 
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd   seven years afterIan Cooper webinar for DDD Iran: Kent beck style tdd   seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
 

Similaire à Making the Unstable Stable - An Intro To Testing

Software presentation
Software presentationSoftware presentation
Software presentationJennaPrengle
 
Myths and reality about software testing
Myths and reality about software testingMyths and reality about software testing
Myths and reality about software testingAlisha Henderson
 
Solving the 3 Biggest Questions in Continuous Testing
Solving the 3 Biggest Questions in Continuous TestingSolving the 3 Biggest Questions in Continuous Testing
Solving the 3 Biggest Questions in Continuous TestingPerfecto by Perforce
 
Software Testing
Software TestingSoftware Testing
Software TestingAdroitLogic
 
Software Testing Interview Questions For Experienced
Software Testing Interview Questions For ExperiencedSoftware Testing Interview Questions For Experienced
Software Testing Interview Questions For Experiencedzynofustechnology
 
Creating a successful continuous testing environment by Eran Kinsbruner
Creating a successful continuous testing environment by Eran KinsbrunerCreating a successful continuous testing environment by Eran Kinsbruner
Creating a successful continuous testing environment by Eran KinsbrunerQA or the Highway
 

Similaire à Making the Unstable Stable - An Intro To Testing (20)

Software presentation
Software presentationSoftware presentation
Software presentation
 
Future of QA
Future of QAFuture of QA
Future of QA
 
Futureofqa
FutureofqaFutureofqa
Futureofqa
 
Automation Concepts
Automation ConceptsAutomation Concepts
Automation Concepts
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Myths and reality about software testing
Myths and reality about software testingMyths and reality about software testing
Myths and reality about software testing
 
Solving the 3 Biggest Questions in Continuous Testing
Solving the 3 Biggest Questions in Continuous TestingSolving the 3 Biggest Questions in Continuous Testing
Solving the 3 Biggest Questions in Continuous Testing
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Software Testing Interview Questions For Experienced
Software Testing Interview Questions For ExperiencedSoftware Testing Interview Questions For Experienced
Software Testing Interview Questions For Experienced
 
Software testing
Software testingSoftware testing
Software testing
 
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
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Creating a successful continuous testing environment by Eran Kinsbruner
Creating a successful continuous testing environment by Eran KinsbrunerCreating a successful continuous testing environment by Eran Kinsbruner
Creating a successful continuous testing environment by Eran Kinsbruner
 
Software testing
Software testingSoftware testing
Software testing
 
Software test proposal
Software test proposalSoftware test proposal
Software test proposal
 
Software testing2
Software testing2Software testing2
Software testing2
 
Software testing
Software testingSoftware testing
Software testing
 
Software testing
Software testingSoftware testing
Software testing
 

Plus de Cameron Presley

Taking a Gamble with Functional Domain Modeling
Taking a Gamble with Functional Domain ModelingTaking a Gamble with Functional Domain Modeling
Taking a Gamble with Functional Domain ModelingCameron Presley
 
Level Up Your Functional Programming Skills with LINQ
Level Up Your Functional Programming Skills with LINQLevel Up Your Functional Programming Skills with LINQ
Level Up Your Functional Programming Skills with LINQCameron Presley
 
Functional Programming Through Construction : First Principles
Functional Programming Through Construction : First PrinciplesFunctional Programming Through Construction : First Principles
Functional Programming Through Construction : First PrinciplesCameron Presley
 
Establishing a SOLID Foundation
Establishing a SOLID FoundationEstablishing a SOLID Foundation
Establishing a SOLID FoundationCameron Presley
 
How Functional Programming Made Me a Better Developer
How Functional Programming Made Me a Better DeveloperHow Functional Programming Made Me a Better Developer
How Functional Programming Made Me a Better DeveloperCameron Presley
 
How to Have Code Reviews That Developers Actually Want
How to Have Code Reviews That Developers Actually WantHow to Have Code Reviews That Developers Actually Want
How to Have Code Reviews That Developers Actually WantCameron Presley
 
Indy Code - Taking a Gamble With F#: Implementing Blackjack
Indy Code - Taking a Gamble With F#: Implementing BlackjackIndy Code - Taking a Gamble With F#: Implementing Blackjack
Indy Code - Taking a Gamble With F#: Implementing BlackjackCameron Presley
 
How Functional Programming Made Me A Better Developer
How Functional Programming Made Me A Better DeveloperHow Functional Programming Made Me A Better Developer
How Functional Programming Made Me A Better DeveloperCameron Presley
 
Establishing a SOLID Foundation - An Intro to Software Design
Establishing a SOLID Foundation - An Intro to Software DesignEstablishing a SOLID Foundation - An Intro to Software Design
Establishing a SOLID Foundation - An Intro to Software DesignCameron Presley
 

Plus de Cameron Presley (9)

Taking a Gamble with Functional Domain Modeling
Taking a Gamble with Functional Domain ModelingTaking a Gamble with Functional Domain Modeling
Taking a Gamble with Functional Domain Modeling
 
Level Up Your Functional Programming Skills with LINQ
Level Up Your Functional Programming Skills with LINQLevel Up Your Functional Programming Skills with LINQ
Level Up Your Functional Programming Skills with LINQ
 
Functional Programming Through Construction : First Principles
Functional Programming Through Construction : First PrinciplesFunctional Programming Through Construction : First Principles
Functional Programming Through Construction : First Principles
 
Establishing a SOLID Foundation
Establishing a SOLID FoundationEstablishing a SOLID Foundation
Establishing a SOLID Foundation
 
How Functional Programming Made Me a Better Developer
How Functional Programming Made Me a Better DeveloperHow Functional Programming Made Me a Better Developer
How Functional Programming Made Me a Better Developer
 
How to Have Code Reviews That Developers Actually Want
How to Have Code Reviews That Developers Actually WantHow to Have Code Reviews That Developers Actually Want
How to Have Code Reviews That Developers Actually Want
 
Indy Code - Taking a Gamble With F#: Implementing Blackjack
Indy Code - Taking a Gamble With F#: Implementing BlackjackIndy Code - Taking a Gamble With F#: Implementing Blackjack
Indy Code - Taking a Gamble With F#: Implementing Blackjack
 
How Functional Programming Made Me A Better Developer
How Functional Programming Made Me A Better DeveloperHow Functional Programming Made Me A Better Developer
How Functional Programming Made Me A Better Developer
 
Establishing a SOLID Foundation - An Intro to Software Design
Establishing a SOLID Foundation - An Intro to Software DesignEstablishing a SOLID Foundation - An Intro to Software Design
Establishing a SOLID Foundation - An Intro to Software Design
 

Dernier

why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 

Dernier (20)

why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 

Making the Unstable Stable - An Intro To Testing

  • 1. Making the Unstable Stable An Introduction to Testing CAMERON PRESLEY @PCAMERONPRESLEY HTTP://BLOG.THESOFTWAREMENTOR.COM
  • 2.
  • 3. Outline ◦Personal Experience ◦Business Case for Testing ◦Intro to Testing ◦Next Steps ◦Additional Resources
  • 4. Tale of Three Companies
  • 5. Company A Large, privately held EMR company Hundreds of developers Very mature codebase
  • 6. Background Team consisted of 3 developers, 2 QA Tool that moved patient info from one hospital to another Errors could lead to data integrity issues
  • 7. Experience Fear of refactoring code (too brittle) Bugs kept coming back Firefighting mode No clear focus
  • 8. What Did I Learn? Bug count never decreased Regressions in functionality Firefighting all the time Relied upon QA to find issues for us
  • 9. Company B Small publicly held company in the healthcare industry Medical diagnostic device with custom hardware Coming into a rewrite of the software
  • 10. Background Team consisted of 3 developers, 1 QA Responsible for calculating test results for given samples Errors could lead to the doctor making the wrong decision
  • 11. Experience Refactored constantly Heavily unit tested components Bugs never came back Clear focus on goals
  • 12. Lessons Learned Bug count decreased and able to focus on new features Confidence that we didn’t break anything (able to change freely) Was it the team or was it testing?
  • 13. Company C Startup in the project management space Help project manager plan “what-if” scenarios Working on the initial release of the software
  • 14. Background Team consisted of 3 developers, 2 QA Responsible for all parts of the application Errors could lead to managers making the wrong decision
  • 15. Experience Lots of bugs Demos would crash ◦ “Pucker factor” Reactive, not proactive
  • 16. Experience Spent time teaching the team how and when to write tests Product began to stabilize Fewer bugs were being found
  • 17. Experience Shipped a massive feature with zero bugs Confidence in the product soared Began to focus on new features
  • 18. Experience When I left, there were over 4,000 tests Entire codebase not covered ◦ Covered major features/functionality Never regressed
  • 19. Personal Experience Testing allows developers to make the changes in a low-risk fashion Software becomes easier to change to reflect new requirements This is pure anecdote, where’s the research?
  • 20. Business Case for Testing
  • 21.
  • 22. Background V1 consisted of 1,000 KLOCs written over the course of 3 years Functional testing (manual testing) was used to ensure the product was working correctly No automated testing was happening ◦ Ad-hoc at best
  • 23. Experiment V2 consisted of 200 KLOCs of new code and 150 KLOCs of changed code Mandated unit tests on new functionality Still relied upon functional testing to ensure no regressions
  • 24. Results During code reviews, reviewers could reject changes due to not enough tests Tests covered 34% of functionality With manual testing, 85% of functionality was covered
  • 25. Results Defect Severity Version 1 Version 2 Severity 1 15.5% 16.8% Severity 2 49.8% 40.1% Severity 3 28.7% 18.8% Severity 4 6.0% 3.4% 21% drop in bugs at a cost of 30% more development time
  • 26. Customers Increased 10x Support Costs Increased 3x
  • 27. Developers’ Perceptions Spent less time fixing bugs Writing tests helped with recognizing error conditions Helped to understand inherited code Felt more comfortable making changes to code
  • 28. Testers’ Perception Code is much higher quality Harder to find bugs, all the obvious ones are gone Able to spend more time looking for more complicated errors Not finding “happy path” bugs
  • 29.
  • 30. Code Complete Implementation Errors Lack of Domain Knowledge Changing Requirements Communication Mishaps What are the top ways bugs are created?
  • 31. Code Complete 80% of all bugs come from 20% of the code 80% of maintenance comes from 20% of the code
  • 32. Code Complete Time Introduced Requirements Architecture Construction System Test Post-Release Requirements 1 3 5-10 10 10-100 Architecture - 1 10 15 25-100 Construction - - 1 10 10-25
  • 33. Automated Testing Can Provide… Examples of what the code should do Built-in documentation A way to make sure requirements are met Common language for everyone
  • 34. The Art of Unit Testing
  • 35. The Art of Unit Testing Stage Without Tests With Tests Implementation 7 14 Integration 7 2 Testing and Bug Fixing Testing Fixing Testing Fixing Testing 3 3 3 2 1 3 1 1 1 1 Total 26 23 Bugs Found In Production 71 11
  • 37. Introducing the Testing Triangle Introduced by Michael Cohn in Succeeding with Agile Breakdown of a test suite ◦ 10% UI ◦ 20% Integration ◦ 70% Unit
  • 39. Parts of a Test (AAA) Arrange – Get code ready to test ◦ Create dependencies, set properties, call methods, etc… Act – Call the code that is being tested ◦ Method, non-trivial property, constructor, etc… Assert – Did we get what we expected? ◦ Throw an exception?, Return an empty list?, Return 42?
  • 41. Types of Automated Tests Unit Tests ◦ Does this one piece work as expected? Integration Tests ◦ Does this one piece work as I’d expect with others? UI/Functional/End-to-End ◦ When performing this workflow, does the application do what I’d expect?
  • 42. Unit Tests “A unit test is an automated piece of code that invokes a unit of work being tested, and then checks some assumptions about a single end result of that unit.” - Roy Osherove (The Art of Unit Testing 2nd Edition)
  • 43. Unit Tests DOES NOT DEPEND UPON EXTERNAL FACTORS! Typically tests a method or non-trivial property Super fast to run (100+ per second) Aren’t likely to change with infrastructure changes
  • 44.
  • 45. Integration Tests “Integration testing is testing a unit of work without having full control over all of it and using one or more real dependencies, such as time, network, database, threads, number generators, and so on.” - Roy Osherove (The Art of Unit Testing 2nd Edition)
  • 46. Integration Tests Tests how your code interacts with databases, networks, 3rd party resources Moderately fast to run (10+ per second) Decently robust, but can be hard to verify correct behavior
  • 47.
  • 48. UI Tests Tests the application by driving the UI Primarily used for end-to-end testing Very slow (takes seconds per test) Very fragile since UI changes can cause the test to break
  • 49. UI Tests Record and play-back ◦Records the interaction between user and application ◦Can be done with QA Coded ◦Specify UI controls by ID or label to interact with ◦Primarily developer driven
  • 50. Tools of the Trade
  • 51. Testing Framework Absolute minimum for writing tests Provides a way to mark classes/methods as tests Allows us to check if result is what we expected ◦ AreEqual, IsTrue, IsFalse, etc…
  • 53. Mocking Framework Unit tests are faster than integration tests Lot of code involves different classes collaborating together How do we unit test these classes? Create test dependencies that we can control ◦ Using interfaces or inheritance
  • 54. Mocking Framework Creates a lot of test code Mocking framework uses reflection to create dependencies Can be used to check that methods/properties were called or to stub a response Examples ◦ NSbustitute, Moq, Mockito
  • 57. UI Framework Provides a mechanism to interact with UI controls Great to provide end-to-end workflow testing Examples ◦Test Stack White (Desktop), Selenium (Web), HP Quick Test Pro
  • 58. Tools of the Trade Testing Framework ◦ Allows us to write tests Mocking Framework ◦ Allows us to switch out real dependencies for fake ones UI Framework ◦ Allows us to interact with the UI components
  • 60. Learning How to Write Tests Sample Exercises ◦Fizz Buzz ◦String Calculator ◦Bowling Game ◦Mars Rover
  • 61. Next Steps Identify Problem Areas Find places in your codebase that have few dependencies ◦ Easier to test and will help build confidence Find places in your codebase that generates bugs ◦ Remember 80% of issues come from 20% of the code ◦ Might need to refactor code to make it testable Don’t know the areas? Ask QA
  • 62. Next Steps Low Impact Testing Don’t have to immediately write tests around everything Start by adding tests on code that you change going forward Just focus on bug fixes ◦ Write a test that fails because the bug exists ◦ Test should pass once the bug is fixed
  • 63. Next Steps Convincing Your Boss Goal is to move applications to production Remember, bugs are more expensive the later they’re found ◦ 25x more expensive if not caught before production Every time QA finds a bug, there’s going to be churn Puts more pressure on QA and the developers
  • 64. If You’re a Manager… Identify those on your team that know how to write tests ◦ Have those developers distribute their knowledge to others Provide training on how to write tests ◦ Pluralsight has some great resources (free 12 month access for all MSDN holders) ◦ The Art of Unit Testing (2nd Edition) by Roy Osherove Incorporate slack time to give developers time to learn
  • 65. Remember! Goal is to decrease time to production, not 100% code coverage Not all applications need tests Not every single line of code needs coverage ◦ 80% of issues come from 20% of the code Be pragmatic, not dogmatic with testing
  • 66. Want to Learn More? 10,000 foot view on testing ◦ Starting to Unit Test: Not as Hard as You Think (e-book) by Erik Dietrich In-Depth Look at Testing ◦ The Art of Unit Testing (2nd Edition) by Roy Osherove Testing Legacy Code ◦ Working Effectively With Legacy Code by Michael Feathers ◦ Refactoring by Martin Fowler
  • 67. Additional Resources Books ◦ Code Complete (2nd Edition) by Steve McConnell Articles ◦ On the Effectiveness of Unit Testing at Microsoft Presentations ◦ Unit Testing Makes Me Faster by Jeremy Clark Videos ◦ Introduction to .NET Testing with NUnit by Jason Roberts

Notes de l'éditeur

  1. Software Engineer at Pilot Flying J (headquartered in Knoxville, TN) – always looking
  2. Over 5,000 employees Responsible for everything between making an appointment and being billed
  3. Allergies not being updated, blood type, etc…
  4. Overall, our bug count never decreased, our QA team was always stressed out and so was I!
  5. #2 – What if the project was cut? Or delayed?
  6. Lead to poor financial decisions that could bankrupt the company
  7. Shipped a massive feature with no bugs - Contractor had originally failed implementing this feature
  8. - Study done by Microsoft and NC state to see if adding unit tests would improve software quality - Compared two versions of software (V1 and V2) - Focused on only adding unit tests to the development process - 32 developers and 28 testers over 2 years
  9. Fundamentals of software architecture, construction, and quality metrics Advice and tips backed up by research, academia, and commercial practice
  10. Fundamentals of writing tests Tips and tricks to work with legacy applications Provides pros and cons of writing tests
  11. 1st -> For example, are those files really being copied over? Is that email being sent? Is the database being manipulated correctly?
  12. Two types of tests