SlideShare a Scribd company logo
1 of 41
@gil_zilberfeld
Introduction to unit
testing
@gil_zilberfeld
Hello!
I AM GIL ZILBERFELD
www.gilzilberfeld.com
www.everydayunittesting.com
@gil_zilberfeld
@gil_zilberfeld
What is testing?
@gil_zilberfeld
Brian
Marick’s
Testing
Quadrants
@gil_zilberfeld
Manual tests
Slow
Do not scale
Encourage forgetfulness
Immoral
@gil_zilberfeld
Automated tests
Run all the time
Don’t complain
Don’t forget
@gil_zilberfeld
The testing
pyramid
http://blogs.agilefaqs.com/2011/02/01/inverting-the-testing-pyramid/
@gil_zilberfeld
Why unit tests?
◉ Quick feedback
◉ Confidence to change your code
◉ Quicker than debugging
◉ Knowing your code works
◉ Low TCO
◉ Small setup overhead
◉ It’s not bugs if it’s caught before QA
◉ Go faster
@gil_zilberfeld
xUnit frameworks
Test identification
Execution and reporting
Asserts
@gil_zilberfeld
C++ xUnit frameworks
CppUnit
Boost Test
Catch
Google Test
@gil_zilberfeld
Java xUnit frameworks
JUnit
TestNG
@gil_zilberfeld
C# xUnit frameworks
NUnit
MSTest
xUnit
@gil_zilberfeld
javascript xUnit frameworks
QUnit
Jasmine
Mocha
@gil_zilberfeld
Demo
The humble lightsaber
@gil_zilberfeld
Make unit tests great again!
What makes them great?
@gil_zilberfeld
Quick
Readable
Focused
Deterministic
Independent
Self-cleaning
Great unit tests are…
@gil_zilberfeld
Refactoring
What is it?
@gil_zilberfeld
Refactoring
◉ Changing the form of the code without changing
the functionality
◉ Safer with tests
◉ But sometimes we need to refactor in order to
test
@gil_zilberfeld
Continuous integration
The mindset, not the tools
@gil_zilberfeld
Unit testing economics
What’s the ROI?
@gil_zilberfeld
Let’s get back to code
Legacy code, that is.
@gil_zilberfeld
Legacy code
◉ Contains all kind of dependencies
◉ Does all kinds of things together
◉ It’s ugly
◉ It’s fragile
◉ It’s rotting
@gil_zilberfeld
Legacy code
It’s hard to unit test
@gil_zilberfeld
Isolation and mocking
Manual
Frameworks
Simulators
@gil_zilberfeld
Mocking frameworks
◉ Test your code for different scenarios
◉ Fake the dependencies
◉ Change behavior of methods
◉ Assert method calls
@gil_zilberfeld
C/C++ mocking frameworks
Google Mock
Hippo Mocks
FFF
… and many more
@gil_zilberfeld
Java mocking frameworks
EasyMock
Mockito
Power Mockito
JMockIt
@gil_zilberfeld
C# mocking frameworks
Moq
FakeItEasy
Isolator
@gil_zilberfeld
javascript mocking frameworks
Sinon.js
@gil_zilberfeld
Demo
@gil_zilberfeld
Tips and tricks
@gil_zilberfeld
Unit testing advice
◉ Think ahead
◉ Make a test plan, not just for unit tests
◉ Test what you’re working on
◉ Unit testing is a team sport
◉ Coverage metrics
@gil_zilberfeld
Unit testing advice
◉ Quick feedback
◉ Organize your tests
◉ The cone of dependency
◉ Name like a detective
◉ Readability first
@gil_zilberfeld
Unit testing advice
◉ Test one thing
◉ Black box vs white box
◉ Test framework emergence
@gil_zilberfeld
Test Driven Development
@gil_zilberfeld
Why test first?
@gil_zilberfeld
Test driven
development
@gil_zilberfeld
Demo: TDD
@gil_zilberfeld
Resources
◉ Michael Feathers
Working effectively with legacy code
◉ “Uncle Bob” Robert Martin
Clean code
The clean coder
◉ Kent Beck
Test driven development by example
Extreme programming explained
@gil_zilberfeld
Resources
◉ James Grenning
Test driven development for embedded C
◉ Martin Fowler
Refactoring: Improving the design of existing code
◉ James Shore
Let’s play TDD
@gil_zilberfeld
Thanks!
ANY QUESTIONS?
You can find me at:
@gil_zilberfeld
http://www.GilZilberfeld.com
http://www.EverydayUnitTesting.com

More Related Content

Viewers also liked

Viewers also liked (6)

Le Tour de xUnit
Le Tour de xUnitLe Tour de xUnit
Le Tour de xUnit
 
xUnit Test Patterns - Chapter19
xUnit Test Patterns - Chapter19xUnit Test Patterns - Chapter19
xUnit Test Patterns - Chapter19
 
Using xUnit as a Swiss-Aarmy Testing Toolkit
Using xUnit as a Swiss-Aarmy Testing ToolkitUsing xUnit as a Swiss-Aarmy Testing Toolkit
Using xUnit as a Swiss-Aarmy Testing Toolkit
 
Mini training - Moving to xUnit.net
Mini training - Moving to xUnit.netMini training - Moving to xUnit.net
Mini training - Moving to xUnit.net
 
ASP.NET Core 2.0 - .NET São Paulo - Outubro-2017
ASP.NET Core 2.0 - .NET São Paulo - Outubro-2017ASP.NET Core 2.0 - .NET São Paulo - Outubro-2017
ASP.NET Core 2.0 - .NET São Paulo - Outubro-2017
 
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
 

Similar to Introduction to Unit Testing

Unit testing the prequel
Unit testing   the prequelUnit testing   the prequel
Unit testing the prequel
Gil Zilberfeld
 

Similar to Introduction to Unit Testing (20)

Zen and the Art of Test Maintenance
Zen and the Art of Test MaintenanceZen and the Art of Test Maintenance
Zen and the Art of Test Maintenance
 
Beter code for better tests
Beter code for better testsBeter code for better tests
Beter code for better tests
 
Unit testing for Grown-ups
Unit testing for Grown-upsUnit testing for Grown-ups
Unit testing for Grown-ups
 
Real Life Test Maintenance
Real Life Test MaintenanceReal Life Test Maintenance
Real Life Test Maintenance
 
Spring Testing Features
Spring Testing FeaturesSpring Testing Features
Spring Testing Features
 
TDD patterns
TDD patternsTDD patterns
TDD patterns
 
7 Steps for writing your first test
7 Steps for writing your first test7 Steps for writing your first test
7 Steps for writing your first test
 
10 Secret Unit Testing Tips
10 Secret Unit Testing Tips10 Secret Unit Testing Tips
10 Secret Unit Testing Tips
 
TDD For The Rest Of Us
TDD For The Rest Of UsTDD For The Rest Of Us
TDD For The Rest Of Us
 
Testing economics101
Testing economics101Testing economics101
Testing economics101
 
Zen And the Art of Test Maintenance Presentation
Zen And the Art of Test Maintenance PresentationZen And the Art of Test Maintenance Presentation
Zen And the Art of Test Maintenance Presentation
 
Unit testing the prequel
Unit testing   the prequelUnit testing   the prequel
Unit testing the prequel
 
Fractal test planning
Fractal test planningFractal test planning
Fractal test planning
 
Continuous Learning - The New ALM
Continuous Learning - The New ALMContinuous Learning - The New ALM
Continuous Learning - The New ALM
 
Spaceship TDD Style
Spaceship TDD StyleSpaceship TDD Style
Spaceship TDD Style
 
Dependency injection and Why It Matters to Testers
Dependency injection and Why It Matters to TestersDependency injection and Why It Matters to Testers
Dependency injection and Why It Matters to Testers
 
Introduction to TDD
Introduction to TDDIntroduction to TDD
Introduction to TDD
 
TDD for the rest of us...
TDD for the rest of us...TDD for the rest of us...
TDD for the rest of us...
 
Zen and the art of Test Maintenance - #TestIL Meetup Tel Aviv
Zen and the art of Test Maintenance - #TestIL Meetup Tel AvivZen and the art of Test Maintenance - #TestIL Meetup Tel Aviv
Zen and the art of Test Maintenance - #TestIL Meetup Tel Aviv
 
An agile introduction to DevOps
An agile introduction to DevOpsAn agile introduction to DevOps
An agile introduction to DevOps
 

More from Gil Zilberfeld

More from Gil Zilberfeld (15)

Dirty tests and How To Clean Them
Dirty tests and How To Clean ThemDirty tests and How To Clean Them
Dirty tests and How To Clean Them
 
Spock: It's Only Logical
Spock: It's Only LogicalSpock: It's Only Logical
Spock: It's Only Logical
 
Better Estimation and Planning
Better Estimation and PlanningBetter Estimation and Planning
Better Estimation and Planning
 
Better Estimation and Planning
Better Estimation and PlanningBetter Estimation and Planning
Better Estimation and Planning
 
The Untold User Story
The Untold User StoryThe Untold User Story
The Untold User Story
 
The Whole Story - Mapping, Slicing and Figuring things out
The Whole Story - Mapping, Slicing and Figuring things outThe Whole Story - Mapping, Slicing and Figuring things out
The Whole Story - Mapping, Slicing and Figuring things out
 
The fastest BDD crash-course ever
The fastest BDD crash-course everThe fastest BDD crash-course ever
The fastest BDD crash-course ever
 
Agile Intro to DevOps
Agile Intro to DevOpsAgile Intro to DevOps
Agile Intro to DevOps
 
Playing games remotely
Playing games remotelyPlaying games remotely
Playing games remotely
 
A Horror Story
A Horror StoryA Horror Story
A Horror Story
 
Work
WorkWork
Work
 
Interview with the Vampire
Interview with the VampireInterview with the Vampire
Interview with the Vampire
 
Simple
SimpleSimple
Simple
 
What is wrong with agile
What is wrong with agileWhat is wrong with agile
What is wrong with agile
 
Rebooting Application Life Cycle Management
Rebooting Application Life Cycle ManagementRebooting Application Life Cycle Management
Rebooting Application Life Cycle Management
 

Recently uploaded

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 

Introduction to Unit Testing