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

More Related Content

What's hot

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

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

Similar to 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
 

Similar to 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
 

Recently uploaded

Recently uploaded (20)

A Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationA Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data Migration
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by Skilrock
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with StrimziStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
Benefits of Employee Monitoring Software
Benefits of  Employee Monitoring SoftwareBenefits of  Employee Monitoring Software
Benefits of Employee Monitoring Software
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 

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

Editor's Notes

  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.