SlideShare a Scribd company logo
1 of 11
Download to read offline
Test Driven Development
Dmitry Savin
Introduction
• TDD is an advanced technique of using automated
unit tests to drive the design of software and force
decoupling of dependencies.
• The result of using this practice is a comprehensive
suite of unit tests that can be run at any time to
provide feedback that the software is still working.
• Was invented by Kent Beck at 1999.
TDD cycle
• Write a test that fails.
• Write just enough code to pass the test.
• Clean up code (remove duplication,
improve the design) and ensure that all
tests still pass.
Write a test that fails
• Imagine how the new code should be called and write the test as if
the code already existed.
• Create the new production code stub. Write just enough code so
that it compiles.
• Run the test. It should fail. By this you ensure that test is calling the
correct code and that the code is not working by accident.
Note
Now we have the goal - make this test pass.

This helps us concentrate our attention on one particular task.
Write just enough code to pass the test
• Write the production code to make the test pass. Keep it simple.
• You can hard-coding of the expected return value first to verify
that the test correctly detects success.
• If you've written the code so that the test passes as intended, you
are finished.
• The test is the objective definition of “done.”
• The phrase "You Ain't Gonna Need It" (YAGNI) is often used to
veto unnecessary work. If new functionality is still needed, then
another test is needed. Make this one test pass and continue.
Clean up code and ensure that all tests
still pass
• Remove duplication caused by the addition of the new functionality.
• Make design changes to improve the overall solution.
• After each refactoring, rerun all the tests to ensure that they all still pass.
Process Example
• Follow these steps (slight variations exist among TDD practitioners):
• Understand the requirements of the story, work item, or feature that you are working
on.
• While working on task you can edit your test list - it is list of tests which you want to
create.
• Red: Create a test and make it fail.
• Green: Make the test pass by any means necessary.
• Refactor: Clean up code and ensure that all tests still pass.
• Repeat the cycle. Each cycle should be very short, and a typical hour should contain
many Red/Green/Refactor cycles.
Benefits of TDD
• The suite of unit tests provides constant feedback that each component is still working.
• The unit tests act as documentation that cannot go out-of-date, unlike separate
documentation, which can and frequently does.
• When the test passes and the production code is refactored to remove duplication, it is
clear that the code is finished, and the developer can move on to a new test.
• Test-driven development forces critical analysis and design because the developer cannot
create the production code without truly understanding what the desired result should be
and how to test it.
• The software tends to be better designed, that is, loosely coupled and easily maintainable,
because the developer is free to make design decisions and refactor at any time with
confidence that the software is still working. This confidence is gained by running the tests.
• The test suite acts as a regression safety net on bugs: If a bug is found, the developer
should create a test to reveal the bug and then modify the production code so that the bug
goes away and all other tests still pass. On each successive test run, all previous bug fixes
are verified.
• Reduced debugging time!
Characteristics of a Good Unit Test
• Runs fast.
• If the tests are slow, they will not be run often.
• Separates or simulates environment dependencies such as databases, file systems, networks,
queues, and so on.
• Otherwise they will not run fast, and a failure does not give meaningful feedback about what the
problem actually is.
• Use stubs and mock objects.
• Is very limited in scope.
• If the test fails, it's obvious where to look for the problem.
• Use few Assert calls so that the broken part of code is obvious.
• It's important to only test one thing in a single test.
• Tests should run and pass on any machine.
• Clearly reveals its intention.
• Another developer can look at the test and understand what is expected of the production code.
Demo
Game “Fifteen Puzzle"
References
• Microsoft: Guidelines for Test-Driven Development
• https://msdn.microsoft.com/en-us/library/aa730844%28v=vs.
80%29.aspx
• MCE 2014: Jon Reid - Test Driven Development for iOS (and anything)
• https://www.youtube.com/watch?v=Jzlz3Bx-NzM

More Related Content

What's hot

Software Testing, Everyone's responsibility
Software Testing, Everyone's responsibilitySoftware Testing, Everyone's responsibility
Software Testing, Everyone's responsibilityKurt Bliefernich
 
TDD and Unit Testing in Golang
TDD and Unit Testing in GolangTDD and Unit Testing in Golang
TDD and Unit Testing in GolangSofian Hadiwijaya
 
Becoming a better programmer - unit testing
Becoming a better programmer - unit testingBecoming a better programmer - unit testing
Becoming a better programmer - unit testingDuy Tan Geek
 
How google-tests-software
How google-tests-softwareHow google-tests-software
How google-tests-softwareBhawna Tuteja
 
Continous testing for grails
Continous testing for grailsContinous testing for grails
Continous testing for grailswinkler1
 
Qa process 2012
Qa process 2012Qa process 2012
Qa process 2012ashokack
 
Testing Attributes
Testing AttributesTesting Attributes
Testing AttributesAbiha Naqvi
 
How QA engineers could affect quality?
How QA engineers could affect quality?How QA engineers could affect quality?
How QA engineers could affect quality?Mikalai Alimenkou
 
01 software testing_introduction
01 software testing_introduction01 software testing_introduction
01 software testing_introductionManishJha237
 
Topic production code
Topic production codeTopic production code
Topic production codeKavi Kumar
 
QA Process Overview for Firefox OS 2014
QA Process Overview for Firefox OS 2014QA Process Overview for Firefox OS 2014
QA Process Overview for Firefox OS 2014Anthony Chung
 
Testing automation in agile environment
Testing automation in agile environmentTesting automation in agile environment
Testing automation in agile environmentPerfecto Mobile
 
Unit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking SkeletonUnit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking SkeletonSeb Rose
 
Project Onion unit test environment
Project Onion unit test environmentProject Onion unit test environment
Project Onion unit test environmentAbhinav Jha
 
Continuous delivery test strategies
Continuous delivery test strategiesContinuous delivery test strategies
Continuous delivery test strategiesHylke Stapersma
 
Keynote AST 2016
Keynote AST 2016Keynote AST 2016
Keynote AST 2016Kim Herzig
 
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...Virtual Forge
 

What's hot (20)

Software Testing, Everyone's responsibility
Software Testing, Everyone's responsibilitySoftware Testing, Everyone's responsibility
Software Testing, Everyone's responsibility
 
TDD and Unit Testing in Golang
TDD and Unit Testing in GolangTDD and Unit Testing in Golang
TDD and Unit Testing in Golang
 
Becoming a better programmer - unit testing
Becoming a better programmer - unit testingBecoming a better programmer - unit testing
Becoming a better programmer - unit testing
 
How google-tests-software
How google-tests-softwareHow google-tests-software
How google-tests-software
 
Continous testing for grails
Continous testing for grailsContinous testing for grails
Continous testing for grails
 
Qa process 2012
Qa process 2012Qa process 2012
Qa process 2012
 
Testing Attributes
Testing AttributesTesting Attributes
Testing Attributes
 
How QA engineers could affect quality?
How QA engineers could affect quality?How QA engineers could affect quality?
How QA engineers could affect quality?
 
CNUG TDD June 2014
CNUG TDD June 2014CNUG TDD June 2014
CNUG TDD June 2014
 
01 software testing_introduction
01 software testing_introduction01 software testing_introduction
01 software testing_introduction
 
Topic production code
Topic production codeTopic production code
Topic production code
 
QA Process Overview for Firefox OS 2014
QA Process Overview for Firefox OS 2014QA Process Overview for Firefox OS 2014
QA Process Overview for Firefox OS 2014
 
Cost of defects
Cost of defectsCost of defects
Cost of defects
 
Testing automation in agile environment
Testing automation in agile environmentTesting automation in agile environment
Testing automation in agile environment
 
Unit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking SkeletonUnit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking Skeleton
 
Project Onion unit test environment
Project Onion unit test environmentProject Onion unit test environment
Project Onion unit test environment
 
Continuous delivery test strategies
Continuous delivery test strategiesContinuous delivery test strategies
Continuous delivery test strategies
 
Keynote AST 2016
Keynote AST 2016Keynote AST 2016
Keynote AST 2016
 
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
 
Regression testing
Regression testingRegression testing
Regression testing
 

Viewers also liked

Bmw tesis iv
Bmw tesis ivBmw tesis iv
Bmw tesis ivAnil More
 
Legal Research Strategies
Legal Research StrategiesLegal Research Strategies
Legal Research StrategiesMatt Cordon
 
Semi final presentation
Semi final presentationSemi final presentation
Semi final presentationLam Guan Xiong
 
Development of the Wi-Fi Offloading Business Concept within the African Marke...
Development of the Wi-Fi Offloading Business Concept within the African Marke...Development of the Wi-Fi Offloading Business Concept within the African Marke...
Development of the Wi-Fi Offloading Business Concept within the African Marke...Beneyam Haile
 
01ข้อมูลและสารสนเทศ
01ข้อมูลและสารสนเทศ01ข้อมูลและสารสนเทศ
01ข้อมูลและสารสนเทศNattipong Siangyen
 
136 Degrees Presentation
136 Degrees Presentation136 Degrees Presentation
136 Degrees PresentationChloe Morris
 
2014-08-18 - A Story
2014-08-18 - A Story2014-08-18 - A Story
2014-08-18 - A StoryAnderson Wang
 
Using puppets in MFL
Using puppets in MFLUsing puppets in MFL
Using puppets in MFLNoeliaRG
 
Coca-Cola TV transmitirá por primera vez para Latinoamérica: Lollapalooza Chile
Coca-Cola TV transmitirá por primera vez para Latinoamérica: Lollapalooza Chile Coca-Cola TV transmitirá por primera vez para Latinoamérica: Lollapalooza Chile
Coca-Cola TV transmitirá por primera vez para Latinoamérica: Lollapalooza Chile Coca-Cola de México
 
Windows 10 A Guide to Secure Mobility in the Enterprise
Windows 10 A Guide to Secure Mobility in the EnterpriseWindows 10 A Guide to Secure Mobility in the Enterprise
Windows 10 A Guide to Secure Mobility in the EnterpriseAGILLY
 

Viewers also liked (15)

Bmw tesis iv
Bmw tesis ivBmw tesis iv
Bmw tesis iv
 
Buen dia
Buen diaBuen dia
Buen dia
 
Pauta numérica (b)
Pauta numérica (b)Pauta numérica (b)
Pauta numérica (b)
 
Legal Research Strategies
Legal Research StrategiesLegal Research Strategies
Legal Research Strategies
 
DKNY
DKNYDKNY
DKNY
 
Semi final presentation
Semi final presentationSemi final presentation
Semi final presentation
 
Development of the Wi-Fi Offloading Business Concept within the African Marke...
Development of the Wi-Fi Offloading Business Concept within the African Marke...Development of the Wi-Fi Offloading Business Concept within the African Marke...
Development of the Wi-Fi Offloading Business Concept within the African Marke...
 
01ข้อมูลและสารสนเทศ
01ข้อมูลและสารสนเทศ01ข้อมูลและสารสนเทศ
01ข้อมูลและสารสนเทศ
 
136 Degrees Presentation
136 Degrees Presentation136 Degrees Presentation
136 Degrees Presentation
 
2014-08-18 - A Story
2014-08-18 - A Story2014-08-18 - A Story
2014-08-18 - A Story
 
Using puppets in MFL
Using puppets in MFLUsing puppets in MFL
Using puppets in MFL
 
Resume
ResumeResume
Resume
 
Coca-Cola TV transmitirá por primera vez para Latinoamérica: Lollapalooza Chile
Coca-Cola TV transmitirá por primera vez para Latinoamérica: Lollapalooza Chile Coca-Cola TV transmitirá por primera vez para Latinoamérica: Lollapalooza Chile
Coca-Cola TV transmitirá por primera vez para Latinoamérica: Lollapalooza Chile
 
Med-Line Singapore Social Media Marketing Plan in 2016
Med-Line Singapore Social Media Marketing Plan in 2016Med-Line Singapore Social Media Marketing Plan in 2016
Med-Line Singapore Social Media Marketing Plan in 2016
 
Windows 10 A Guide to Secure Mobility in the Enterprise
Windows 10 A Guide to Secure Mobility in the EnterpriseWindows 10 A Guide to Secure Mobility in the Enterprise
Windows 10 A Guide to Secure Mobility in the Enterprise
 

Similar to Tdd

Week 14 Unit Testing.pptx
Week 14  Unit Testing.pptxWeek 14  Unit Testing.pptx
Week 14 Unit Testing.pptxmianshafa
 
Test driven development
Test driven developmentTest driven development
Test driven developmentHarry Potter
 
Test driven development
Test driven developmentTest driven development
Test driven developmentLuis Goldster
 
Test driven development
Test driven developmentTest driven development
Test driven developmentTony Nguyen
 
Test driven development
Test driven developmentTest driven development
Test driven developmentYoung Alista
 
Test driven development
Test driven developmentTest driven development
Test driven developmentJames Wong
 
Test driven development
Test driven developmentTest driven development
Test driven developmentFraboni Ec
 
Test driven developement
Test driven developementTest driven developement
Test driven developementBhavik Panchal
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit TestingSahar Nofal
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentnikhil sreeni
 
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)Peter Kofler
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference CardSeapine Software
 
Automated testing overview
Automated testing overviewAutomated testing overview
Automated testing overviewAlex Pop
 

Similar to Tdd (20)

Week 14 Unit Testing.pptx
Week 14  Unit Testing.pptxWeek 14  Unit Testing.pptx
Week 14 Unit Testing.pptx
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven developement
Test driven developementTest driven developement
Test driven developement
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Lecture 21
Lecture 21Lecture 21
Lecture 21
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Unit Testing talk
Unit Testing talkUnit Testing talk
Unit Testing talk
 
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
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Istqb foundation level day 1
Istqb foundation level   day 1Istqb foundation level   day 1
Istqb foundation level day 1
 
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)
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
 
Automated testing overview
Automated testing overviewAutomated testing overview
Automated testing overview
 

Tdd

  • 2. Introduction • TDD is an advanced technique of using automated unit tests to drive the design of software and force decoupling of dependencies. • The result of using this practice is a comprehensive suite of unit tests that can be run at any time to provide feedback that the software is still working. • Was invented by Kent Beck at 1999.
  • 3. TDD cycle • Write a test that fails. • Write just enough code to pass the test. • Clean up code (remove duplication, improve the design) and ensure that all tests still pass.
  • 4. Write a test that fails • Imagine how the new code should be called and write the test as if the code already existed. • Create the new production code stub. Write just enough code so that it compiles. • Run the test. It should fail. By this you ensure that test is calling the correct code and that the code is not working by accident. Note Now we have the goal - make this test pass.
 This helps us concentrate our attention on one particular task.
  • 5. Write just enough code to pass the test • Write the production code to make the test pass. Keep it simple. • You can hard-coding of the expected return value first to verify that the test correctly detects success. • If you've written the code so that the test passes as intended, you are finished. • The test is the objective definition of “done.” • The phrase "You Ain't Gonna Need It" (YAGNI) is often used to veto unnecessary work. If new functionality is still needed, then another test is needed. Make this one test pass and continue.
  • 6. Clean up code and ensure that all tests still pass • Remove duplication caused by the addition of the new functionality. • Make design changes to improve the overall solution. • After each refactoring, rerun all the tests to ensure that they all still pass.
  • 7. Process Example • Follow these steps (slight variations exist among TDD practitioners): • Understand the requirements of the story, work item, or feature that you are working on. • While working on task you can edit your test list - it is list of tests which you want to create. • Red: Create a test and make it fail. • Green: Make the test pass by any means necessary. • Refactor: Clean up code and ensure that all tests still pass. • Repeat the cycle. Each cycle should be very short, and a typical hour should contain many Red/Green/Refactor cycles.
  • 8. Benefits of TDD • The suite of unit tests provides constant feedback that each component is still working. • The unit tests act as documentation that cannot go out-of-date, unlike separate documentation, which can and frequently does. • When the test passes and the production code is refactored to remove duplication, it is clear that the code is finished, and the developer can move on to a new test. • Test-driven development forces critical analysis and design because the developer cannot create the production code without truly understanding what the desired result should be and how to test it. • The software tends to be better designed, that is, loosely coupled and easily maintainable, because the developer is free to make design decisions and refactor at any time with confidence that the software is still working. This confidence is gained by running the tests. • The test suite acts as a regression safety net on bugs: If a bug is found, the developer should create a test to reveal the bug and then modify the production code so that the bug goes away and all other tests still pass. On each successive test run, all previous bug fixes are verified. • Reduced debugging time!
  • 9. Characteristics of a Good Unit Test • Runs fast. • If the tests are slow, they will not be run often. • Separates or simulates environment dependencies such as databases, file systems, networks, queues, and so on. • Otherwise they will not run fast, and a failure does not give meaningful feedback about what the problem actually is. • Use stubs and mock objects. • Is very limited in scope. • If the test fails, it's obvious where to look for the problem. • Use few Assert calls so that the broken part of code is obvious. • It's important to only test one thing in a single test. • Tests should run and pass on any machine. • Clearly reveals its intention. • Another developer can look at the test and understand what is expected of the production code.
  • 11. References • Microsoft: Guidelines for Test-Driven Development • https://msdn.microsoft.com/en-us/library/aa730844%28v=vs. 80%29.aspx • MCE 2014: Jon Reid - Test Driven Development for iOS (and anything) • https://www.youtube.com/watch?v=Jzlz3Bx-NzM