SlideShare une entreprise Scribd logo
1  sur  15
Unit Tests 101
Slow down to go faster
About me
● Guy Yogev
○ ~3.5 years at Spectory HQ
○ ~1 year at Google Trends Team
● gyogev@google.com
● guyogev @bitbucket
Why testing makes development faster
The classic code review:
● Reviewer: “Did we unit test this code?”
● developer: “We don’t have time for that!”
Why testing makes development faster (cont...)
Why testing makes development faster (cont...)
Dev cycle - without unit testing
Design Write Code Verify it
works
QA
Why testing makes development faster (cont...)
Dev cycle - unit testing after code is done.
Design Write Code Verify it
works
QAWrite tests
Why testing makes development faster (cont...)
Dev cycle with test automation (TDD)
Design Write code +
tests
Verify it
works
QA
Other benefits
Unit tests at the foundation of good software, some of the benefits:
1. Discovers bugs early
a. Test failure indicates some part is not working as intended, which usually means a bug.
2. Makes refactoring easier
a. Change the unit internals without changing its interface & behavior.
3. Documentation
a. Text docs are often neglected as the code grows.
b. Unit tests supply small working examples for our unit in action, that is always up to date.
4. Design
a. Complex code leads complex tests.
What is a unit?
The smallest testable part of an application (wiki)
● Entire module
● Single function
It doesn’t matter which test framework we use, the test structure is pretty much the same
● Senario (describe/context/testsuite...)
○ Setup (before/beforeEach/beforeAll...)
○ Tests (it/should...)
○ Tear-down (after/afterEach/afterAll...)
Some frameworks support nesting scenarios.
Unit test structure
Example (TDD)
Example (Tests as docs)
Example (Code Architecture)
Further readings
● Test suite robustness
● Test Doubles For Dummies
● Code coverage
Thanks!
gyogev@google.com

Contenu connexe

Tendances

Agile Process Management and tools
Agile Process Management and toolsAgile Process Management and tools
Agile Process Management and tools
osama khalid
 

Tendances (20)

Agile Testing Vs V
Agile Testing Vs VAgile Testing Vs V
Agile Testing Vs V
 
QA and scrum
QA and scrumQA and scrum
QA and scrum
 
QA in Agile
QA in AgileQA in Agile
QA in Agile
 
Extreme Programming - to the next-level
Extreme Programming - to the next-levelExtreme Programming - to the next-level
Extreme Programming - to the next-level
 
Testing & Scrum
Testing & ScrumTesting & Scrum
Testing & Scrum
 
QA Fest 2017. Владимир Примаков. QA метрики. Взгляд на качество с разных стор...
QA Fest 2017. Владимир Примаков. QA метрики. Взгляд на качество с разных стор...QA Fest 2017. Владимир Примаков. QA метрики. Взгляд на качество с разных стор...
QA Fest 2017. Владимир Примаков. QA метрики. Взгляд на качество с разных стор...
 
Continuous Delivery Presentation
Continuous Delivery PresentationContinuous Delivery Presentation
Continuous Delivery Presentation
 
Agile Process Management and tools
Agile Process Management and toolsAgile Process Management and tools
Agile Process Management and tools
 
Testing activities in continuous integration and continuous delivery as an ex...
Testing activities in continuous integration and continuous delivery as an ex...Testing activities in continuous integration and continuous delivery as an ex...
Testing activities in continuous integration and continuous delivery as an ex...
 
Testing activities in CI/CD as exploratory tester
Testing activities in CI/CD as exploratory testerTesting activities in CI/CD as exploratory tester
Testing activities in CI/CD as exploratory tester
 
User story workflow (eng)
User story workflow (eng)User story workflow (eng)
User story workflow (eng)
 
Testing in java
Testing in javaTesting in java
Testing in java
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
 
Fast end-to-end-tests
Fast end-to-end-testsFast end-to-end-tests
Fast end-to-end-tests
 
Btd presentation-2011
Btd presentation-2011Btd presentation-2011
Btd presentation-2011
 
A Test Manifesto 2014.03.26
A Test Manifesto 2014.03.26A Test Manifesto 2014.03.26
A Test Manifesto 2014.03.26
 
Agile testing for large projects
Agile testing for large projectsAgile testing for large projects
Agile testing for large projects
 
Automated Performance Testing
Automated Performance TestingAutomated Performance Testing
Automated Performance Testing
 
Test automation in agile ecosystem
Test automation in agile ecosystemTest automation in agile ecosystem
Test automation in agile ecosystem
 
Testing: Heaven or Hell
Testing: Heaven or HellTesting: Heaven or Hell
Testing: Heaven or Hell
 

Similaire à Unit tests 101

Einführung Test-driven Development
Einführung Test-driven DevelopmentEinführung Test-driven Development
Einführung Test-driven Development
Timo Stollenwerk
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
BestBrains
 
Alexandru Bolboaca - Unit Testing from the Trenches
Alexandru Bolboaca - Unit Testing from the TrenchesAlexandru Bolboaca - Unit Testing from the Trenches
Alexandru Bolboaca - Unit Testing from the Trenches
Mozaic Works
 
Becoming a better programmer - unit testing
Becoming a better programmer - unit testingBecoming a better programmer - unit testing
Becoming a better programmer - unit testing
Duy Tan Geek
 

Similaire à Unit tests 101 (20)

TDD and Unit Testing in Golang
TDD and Unit Testing in GolangTDD and Unit Testing in Golang
TDD and Unit Testing in Golang
 
Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Concepts
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)
 
Einführung Test-driven Development
Einführung Test-driven DevelopmentEinführung Test-driven Development
Einführung Test-driven Development
 
Test driven development_continuous_integration
Test driven development_continuous_integrationTest driven development_continuous_integration
Test driven development_continuous_integration
 
The Test way
The Test wayThe Test way
The Test way
 
A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)
 
Agile Mëtteg #5: Agile Testing
Agile Mëtteg #5: Agile TestingAgile Mëtteg #5: Agile Testing
Agile Mëtteg #5: Agile Testing
 
Quality Assurance: An Overview
Quality Assurance: An OverviewQuality Assurance: An Overview
Quality Assurance: An Overview
 
Agile Testing - What is it?
Agile Testing - What is it?Agile Testing - What is it?
Agile Testing - What is it?
 
Agile Testing
Agile Testing  Agile Testing
Agile Testing
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
 
Alexandru Bolboaca - Unit Testing from the Trenches
Alexandru Bolboaca - Unit Testing from the TrenchesAlexandru Bolboaca - Unit Testing from the Trenches
Alexandru Bolboaca - Unit Testing from the Trenches
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Automated Unit Testing and TDD
Automated Unit Testing and TDDAutomated Unit Testing and TDD
Automated Unit Testing and TDD
 
Becoming a better programmer - unit testing
Becoming a better programmer - unit testingBecoming a better programmer - unit testing
Becoming a better programmer - unit testing
 
Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)
 
Methodology: IT test
Methodology: IT testMethodology: IT test
Methodology: IT test
 
Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy
 

Dernier

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Dernier (20)

%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
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...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
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
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%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
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%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
 
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...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 

Unit tests 101

  • 1. Unit Tests 101 Slow down to go faster
  • 2. About me ● Guy Yogev ○ ~3.5 years at Spectory HQ ○ ~1 year at Google Trends Team ● gyogev@google.com ● guyogev @bitbucket
  • 3. Why testing makes development faster The classic code review: ● Reviewer: “Did we unit test this code?” ● developer: “We don’t have time for that!”
  • 4. Why testing makes development faster (cont...)
  • 5. Why testing makes development faster (cont...) Dev cycle - without unit testing Design Write Code Verify it works QA
  • 6. Why testing makes development faster (cont...) Dev cycle - unit testing after code is done. Design Write Code Verify it works QAWrite tests
  • 7. Why testing makes development faster (cont...) Dev cycle with test automation (TDD) Design Write code + tests Verify it works QA
  • 8. Other benefits Unit tests at the foundation of good software, some of the benefits: 1. Discovers bugs early a. Test failure indicates some part is not working as intended, which usually means a bug. 2. Makes refactoring easier a. Change the unit internals without changing its interface & behavior. 3. Documentation a. Text docs are often neglected as the code grows. b. Unit tests supply small working examples for our unit in action, that is always up to date. 4. Design a. Complex code leads complex tests.
  • 9. What is a unit? The smallest testable part of an application (wiki) ● Entire module ● Single function
  • 10. It doesn’t matter which test framework we use, the test structure is pretty much the same ● Senario (describe/context/testsuite...) ○ Setup (before/beforeEach/beforeAll...) ○ Tests (it/should...) ○ Tear-down (after/afterEach/afterAll...) Some frameworks support nesting scenarios. Unit test structure
  • 14. Further readings ● Test suite robustness ● Test Doubles For Dummies ● Code coverage

Notes de l'éditeur

  1. Bugs are easier to fix when caught early in the process. Debugging takes time too
  2. Every step is manual.
  3. When feature is ready, lock it behavior with unit tests
  4. The behavior is locked BEFORE the feature is done - automation of the verification step.
  5. Ask 2. How can test make refactoring easier? 3. What’s wrong with regular docs? 4. How can test improve software design
  6. Entire modules ofter is hard to test. Methods within the module are easier to test. Pure functions are the easiest.