SlideShare a Scribd company logo
Hicham El Hammouchi
@helhammo
www.hichamelhammouchi.com
https://github.com/melxx001
§ Introduction
§ What is a unit test?
§ What is TDD?
§ Why use TDD?
§ TDD Misconceptions
§ Are Unit test Useless?
§ What’s a good unit test?
§ Unit vs functional vs Integration
§ How to start TDD at work
§ Summary
§ Demo
§ Tests are the first line of the defense
§ Enhance documentation
§ Help design your code
§ Help in refactoring, adding, modifying or removing features
§ Help in preventing broken builds to production
§ Help in developer understand the component requirement
§ Very clearly defined purpose and set of attributes
§ ONE specific requirement for ONE specific method
§ Targeted
§ Isolated
§ Repeatable
§ Independent
§ Encourages Simplification
§ "Test-driven development (TDD) is a software development process that relies on
the repetition of a very short development cycle: requirements are turned into very
specific test cases, then the software is improved to pass the new tests, only." -
WikipediA
§ Write a failing test (Red)
§ Implement the code and make the test pass (Green)
§ Refactor (If needed)
§ TDD reduces production bug density by 40–80% (based on studies)
§ Reduces maintenance costs
§ Increase developer productivity in the long term
§ Encourage more modular design
§ Reduces code complexity
§ Reduces the interruption of the normal flow of software development
§ It's too time consuming
§ You can't write test until you know the design and implement the code
§ You have to write all tests before you write the code
§ Everything needs unit tests
§ Brittle tests
§ Complicated tests
§ Ignored Tests
§ Follow Best Practices
§ Robust tests
§ Do and Learn
§ Design aid
§ Feature documentation
§ QA/Continuous Delivery
§ Good Bug Report
§ Exact location of issue
§ Quick
§ Ideally, test would run constantly
§ Which component was tested?
§ What is the expected behavior?
§ What's the expected result?
§ What was the actual output?
§ How can the test be reproduced?
§ Unit tests ensure that individual components of the app work as expected
§ Integration tests ensure that component collaborations work as expected
§ Functional tests ensure that the app works as expected from the user’s perspective
§ Ideally, we'd start a new project with TDD
§ Start a new task with unit tests
§ Fix bugs with unit tests if possible
§ TDD
§ Write a failing test (Red)
§ Implement the code and make the test pass (Green)
§ Refactor (If needed)
§ Guidelines of successful tests
§ One assertion per test
§ Test output produces clear documentation
§ Tests are simple and understandable at a glance
§ Tests are treated like code
§ Which component was tested?
§ What is the expected behavior?
§ What's the expected result?
§ What was the actual output?
§ How can the test be reprod uced?
§ TDD does not replace architecture or Design
§ TDD will inform and validate (or not) your design
§ Weakness and flaws in design will be uncovered
§ Finding bugs in development is much better than finding them in production
§ “Perfect is the enemy of good.”Voltaire
§ 5 Questions Every Unit Test Must Answer - https://medium.com/javascript-
scene/what-every-unit-test-needs-f6cd34d9836d
§ 5 Common Misconceptions About TDD & Unit Tests -
https://medium.com/javascript-scene/5-common-misconceptions-about-
tdd-unit-tests-863d5beb3ce9
§ Empirical Studies Show Test Driven Development Improves Quality -
https://www.infoq.com/news/2009/03/TDD-Improves-Quality
Test Driven Development
Test Driven Development

More Related Content

What's hot (20)

PDF
Behavior Driven Development—A Guide to Agile Practices by Josh Eastman
QA or the Highway
 
PPTX
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
Steve Lange
 
PDF
Impression from Geecon 2014
Adamsus
 
PPTX
Continuous business goal validation
Hylke Stapersma
 
PPTX
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
Steve Lange
 
PPTX
Continuous delivery test strategies
Hylke Stapersma
 
PDF
TLC2018 Shyam Sunder: Legoizing Testing
Anna Royzman
 
PDF
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
JAXLondon2014
 
PPTX
Agile Testing in Enterprise: Way to transform - SQA Days 2014
Andrey Rebrov
 
PDF
Hey You Got Your TDD in my SQL DB by Jeff McKenzie
QA or the Highway
 
PDF
Test pyramid
Poornima Durairaj
 
ODP
Agileee 2012
Wiktor Żołnowski
 
PDF
How testers add value to the organization appium conf
Corina Pip
 
PDF
The Essentials Of Test Driven Development
Rock Interview
 
PDF
Automation testing in Agile project
Hien Nguyen
 
PDF
Testing: the more you do it, the more you'll like it
Jeffrey McGuire
 
PPS
Test Driven Development by Sameer Arora
Xebia IT Architects
 
PDF
Become Software Tester or Developer
KMS Technology
 
PDF
[XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015]
Agile đây Vietnam
 
PDF
Improving the Quality of Incoming Code
Naresh Jain
 
Behavior Driven Development—A Guide to Agile Practices by Josh Eastman
QA or the Highway
 
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
Steve Lange
 
Impression from Geecon 2014
Adamsus
 
Continuous business goal validation
Hylke Stapersma
 
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
Steve Lange
 
Continuous delivery test strategies
Hylke Stapersma
 
TLC2018 Shyam Sunder: Legoizing Testing
Anna Royzman
 
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
JAXLondon2014
 
Agile Testing in Enterprise: Way to transform - SQA Days 2014
Andrey Rebrov
 
Hey You Got Your TDD in my SQL DB by Jeff McKenzie
QA or the Highway
 
Test pyramid
Poornima Durairaj
 
Agileee 2012
Wiktor Żołnowski
 
How testers add value to the organization appium conf
Corina Pip
 
The Essentials Of Test Driven Development
Rock Interview
 
Automation testing in Agile project
Hien Nguyen
 
Testing: the more you do it, the more you'll like it
Jeffrey McGuire
 
Test Driven Development by Sameer Arora
Xebia IT Architects
 
Become Software Tester or Developer
KMS Technology
 
[XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015]
Agile đây Vietnam
 
Improving the Quality of Incoming Code
Naresh Jain
 

Similar to Test Driven Development (20)

PPTX
Test Driven Development
Md. Enamul Haque Chowdhury
 
PDF
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
PPTX
Test driven development
namkha87
 
PDF
Tdd
Dmitry Savin
 
PPTX
Test-Driven Development
Meilan Ou
 
PDF
TDD in Javascript
Mathieu Breton
 
PPTX
TDD in Agile
Atish Narlawar
 
PDF
Test Driven Development (TDD)
David Ehringer
 
PPT
Unit Testing, TDD and the Walking Skeleton
Seb Rose
 
PPT
Automated Unit Testing and TDD
Greg Sohl
 
PDF
Test Driven iOS Development (TDD)
Babul Mirdha
 
PPTX
Test-Driven Development In Action
Jon Kruger
 
PPTX
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Cefalo
 
PPTX
A Brief Introduction to Test-Driven Development
Shawn Jones
 
PDF
Getting started with Test Driven Development
Ferdous Mahmud Shaon
 
PPTX
2016 10-04: tdd++: tdd made easier
Christian Hujer
 
PPTX
Test Driven Development - a gentle introduction
Sergei Kukharev
 
PDF
Test Drive Development
satya sudheer
 
PDF
Unit testing - An introduction
Alejandro Claro Mosqueda
 
Test Driven Development
Md. Enamul Haque Chowdhury
 
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
Test driven development
namkha87
 
Test-Driven Development
Meilan Ou
 
TDD in Javascript
Mathieu Breton
 
TDD in Agile
Atish Narlawar
 
Test Driven Development (TDD)
David Ehringer
 
Unit Testing, TDD and the Walking Skeleton
Seb Rose
 
Automated Unit Testing and TDD
Greg Sohl
 
Test Driven iOS Development (TDD)
Babul Mirdha
 
Test-Driven Development In Action
Jon Kruger
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Cefalo
 
A Brief Introduction to Test-Driven Development
Shawn Jones
 
Getting started with Test Driven Development
Ferdous Mahmud Shaon
 
2016 10-04: tdd++: tdd made easier
Christian Hujer
 
Test Driven Development - a gentle introduction
Sergei Kukharev
 
Test Drive Development
satya sudheer
 
Unit testing - An introduction
Alejandro Claro Mosqueda
 
Ad

Recently uploaded (20)

PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PPTX
Online Cab Booking and Management System.pptx
diptipaneri80
 
PPTX
Information Retrieval and Extraction - Module 7
premSankar19
 
PPTX
MULTI LEVEL DATA TRACKING USING COOJA.pptx
dollysharma12ab
 
PPTX
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
PPTX
ENSA_Module_7.pptx_wide_area_network_concepts
RanaMukherjee24
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PDF
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
PDF
Jual GPS Geodetik CHCNAV i93 IMU-RTK Lanjutan dengan Survei Visual
Budi Minds
 
PPTX
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
PDF
Zero carbon Building Design Guidelines V4
BassemOsman1
 
PPTX
Ground improvement techniques-DEWATERING
DivakarSai4
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
PPTX
Basics of Auto Computer Aided Drafting .pptx
Krunal Thanki
 
PPTX
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
PDF
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
Online Cab Booking and Management System.pptx
diptipaneri80
 
Information Retrieval and Extraction - Module 7
premSankar19
 
MULTI LEVEL DATA TRACKING USING COOJA.pptx
dollysharma12ab
 
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
ENSA_Module_7.pptx_wide_area_network_concepts
RanaMukherjee24
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
Inventory management chapter in automation and robotics.
atisht0104
 
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
Jual GPS Geodetik CHCNAV i93 IMU-RTK Lanjutan dengan Survei Visual
Budi Minds
 
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
Zero carbon Building Design Guidelines V4
BassemOsman1
 
Ground improvement techniques-DEWATERING
DivakarSai4
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
Basics of Auto Computer Aided Drafting .pptx
Krunal Thanki
 
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
Ad

Test Driven Development

  • 2. § Introduction § What is a unit test? § What is TDD? § Why use TDD? § TDD Misconceptions § Are Unit test Useless? § What’s a good unit test? § Unit vs functional vs Integration § How to start TDD at work § Summary § Demo
  • 3. § Tests are the first line of the defense § Enhance documentation § Help design your code § Help in refactoring, adding, modifying or removing features § Help in preventing broken builds to production § Help in developer understand the component requirement
  • 4. § Very clearly defined purpose and set of attributes § ONE specific requirement for ONE specific method
  • 5. § Targeted § Isolated § Repeatable § Independent § Encourages Simplification
  • 6. § "Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: requirements are turned into very specific test cases, then the software is improved to pass the new tests, only." - WikipediA
  • 7. § Write a failing test (Red) § Implement the code and make the test pass (Green) § Refactor (If needed)
  • 8. § TDD reduces production bug density by 40–80% (based on studies) § Reduces maintenance costs § Increase developer productivity in the long term § Encourage more modular design § Reduces code complexity § Reduces the interruption of the normal flow of software development
  • 9. § It's too time consuming § You can't write test until you know the design and implement the code § You have to write all tests before you write the code § Everything needs unit tests
  • 10. § Brittle tests § Complicated tests § Ignored Tests
  • 11. § Follow Best Practices § Robust tests § Do and Learn
  • 12. § Design aid § Feature documentation § QA/Continuous Delivery
  • 13. § Good Bug Report § Exact location of issue
  • 14. § Quick § Ideally, test would run constantly
  • 15. § Which component was tested? § What is the expected behavior? § What's the expected result? § What was the actual output? § How can the test be reproduced?
  • 16. § Unit tests ensure that individual components of the app work as expected § Integration tests ensure that component collaborations work as expected § Functional tests ensure that the app works as expected from the user’s perspective
  • 17. § Ideally, we'd start a new project with TDD § Start a new task with unit tests § Fix bugs with unit tests if possible
  • 18. § TDD § Write a failing test (Red) § Implement the code and make the test pass (Green) § Refactor (If needed)
  • 19. § Guidelines of successful tests § One assertion per test § Test output produces clear documentation § Tests are simple and understandable at a glance § Tests are treated like code
  • 20. § Which component was tested? § What is the expected behavior? § What's the expected result? § What was the actual output? § How can the test be reprod uced?
  • 21. § TDD does not replace architecture or Design § TDD will inform and validate (or not) your design § Weakness and flaws in design will be uncovered § Finding bugs in development is much better than finding them in production § “Perfect is the enemy of good.”Voltaire
  • 22. § 5 Questions Every Unit Test Must Answer - https://medium.com/javascript- scene/what-every-unit-test-needs-f6cd34d9836d § 5 Common Misconceptions About TDD & Unit Tests - https://medium.com/javascript-scene/5-common-misconceptions-about- tdd-unit-tests-863d5beb3ce9 § Empirical Studies Show Test Driven Development Improves Quality - https://www.infoq.com/news/2009/03/TDD-Improves-Quality

Editor's Notes

  • #4: We all know that we should write unit tests to prevent defects but a lot of us don't really know the essential ingredients of unit testing.   To have something reliable and durable, you can't just grab things and see if it fits together. There are specification to each component of the system. There are checkpoints to make sure each part of the system is successful Each individual component Interaction of groups of component Workings as a whole Tests are the first line of the defense and will ensure the success of application. In addition of making sure the system is working correctly, test can also: Enhance existing (or not) documentation by showing an example of implementation Help design your code Help in refactoring, adding, modifying or removing features Help in preventing broken builds to production Help in developer understand the component requirement. The difficult things and surprises are tackled early on
  • #5: Before we can get into a discussion of exactly what TDD is and how it works, it’s important to have a common and defined understanding about what a unit test is. A unit test is a very specific type of test with a very clearly defined purpose and set of attributes. It tests ONE specific requirement for ONE specific method
  • #6: They have the following attributes: Targeted: test one thing, one set of inputs at a time Isolated: The code tested should be isolated (from other code and external dependencies or events) Repeatable/Predictable: if the code and test did not change, running the test any amount of time will produce the same result Independent: Unit tests should be able to be run in any order. They should not expect or require that they follow a certain sequence Encourages Simplification: If the testing of the function is too complex then most likely the function is doing too much
  • #7: "Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: requirements are turned into very specific test cases, then the software is improved to pass the new tests, only." - Wikipedia
  • #8: So: Write a failing test (Usually displayed in Red) Implement the code and make the test pass (Usually displayed in Green) Refactor (If some issue with performance or really bad code)
  • #9: The benefits of TDD have been tested on real projects by companies like Microsoft and IBM, and they found that the TDD process is enormously beneficial. Check out https://www.infoq.com/news/2009/03/TDD-Improves-Quality TDD reduces production bug density by 40–80%. Says 90% in study. Reduces maintenance costs: The teams' management reported subjectively a 15–35% increase in initial development time for the teams using TDD, though the teams agreed that this was offset by reduced maintenance costs Increase developer productivity in the long term Encourage more modular design Reduces code complexity Reduces the interruption of the normal flow of software development Increase things like user retention, increase of users (Probably not at C1) Reduce customer abandonment (Probably not at C1) Reduce the costs of customer service (probably not at C1)
  • #10: I hear this all the time: It's too time consuming: While the process adds 10%-30% to initial development, over time, when you factor maintenance, bug fixes rewrites, this offsets in maintenance costs You can't write test until you know the design and implement the code. Studies have concluded that writing tests first is more effective than adding tests later (TDD reduces production bug density by 40–90%). TDD forces you have a direction in mind before you start and having a better direction leads to better design You have to write all tests before you write the code. Not true. We try things and explore options until we get the result we want Everything needs unit tests: If you have to do a lot of mocking, perhaps that code doesn’t need a unit test. Maybe a functional tests would be better.
  • #11: Badly designed and written tests can cause more pain than help. The trouble with tests: You can have Brittle tests: easy to break You can have Complicated tests: Cost developer time to understand the test Ignored Tests: When test repeatedly fails, developers loose confidence in validity and mark them as ignored. It happens all the time with false positives.
  • #12: How to make them work Follow Best Practices: Write tests like real code Robust tests: Test the right things Do and Learn Code, code, code The more you code, the easier it gets
  • #13: So what’s a good unit test? Features Design aid: written during design phase, prior to implementation Feature documentation & test of developer understanding: The test should provide a clear description of the feature being tested QA/Continuous Delivery: The tests should halt the delivery pipeline on failure and produce a good bug report when they fail
  • #14: Need a good bug report The failure report should be able to show you exactly what failed and where to look
  • #15: Built for speed Running test should be quick and simple. Ideally, constantly running in the background.
  • #16: Questions to ask These are the 5 questions a unit test should easily answer when you look at it Which component was tested? What is the expected behavior? What's the expected result? What was the actual output? How can the test be reproduced?
  • #17: Unit tests ensure that individual components of the app work as expected. Assertions test the component API Integration tests ensure that component collaborations work as expected. Assertions may test component API, UI, or side-effects (such as database I/O, logging, etc.…) Functional tests ensure that the app works as expected from the user’s perspective. Assertions primarily test the user interface
  • #18: For your current project, how do you start TDD? Ideally, we'd start a new project with TDD Start a new task with unit tests Fix bugs with unit tests if possible
  • #19: In summary, TDD is a good process to deliver better quality code and gives more confidence in delivery The TDD cycle is: Write a failing test (Red) Implement the code and make the test pass (Green) Refactor (If some issue with performance or really bad code)
  • #20: One assertion per test (except when it makes sense. For example, checking if a function exists and is not null) If many things are tested at once, you'll have to unravel the results The test can become difficult to understand (show good test vs crappy test) Test output produces clear documentation Naming the test with a specific naming convention (what's been tested, test conditions, expectation) Tests are simple and understandable at a glance Should be able to look at it and understand it immediately Shouldn't be branching & looping Tests are treated like code: refactored, optimized and improved Easy to maintain & extend Don't repeat yourself
  • #21: Questions to ask These are the 5 questions a unit test should easily answer when you look at it Which component was tested? What is the expected behavior? What's the expected result? What was the actual output? How can the test be reproduced?
  • #22: It’s a learning curve and it takes time to get the hang of it. A lot of times, it’s takes discipline to do it. Especially when you have deadlines and someone breathing down your neck. TDD does not replace architecture or Design (You need to do some up front design and have a vision) TDD will inform and validate (or not) your design Weakness and flaws in design will be uncovered Finding bugs in development is much better than finding them in production “Perfect is the enemy of good.” Voltaire