SlideShare a Scribd company logo
TEST DRIVEN DEVELOPMENT
      DPUG - 09/08/2009 - Jason Ragsdale




                      1
What is TDD?

  Test-driven development (TDD) is a software development technique
  that relies on the repetition of a very short development cycle:

1. First write a failing automated test case that defines a desired
   improvement or new function

2. Then produce code to pass that test

3. Finally refactor the new code to acceptable standards.



                                        2
The Three Laws of TDD


1. Don’t write any code unless it is to make a failing test pass.

2. Don’t write any more of a unit test than is sufficient to fail.

3. Don’t write more code than is sufficient to pass the one failing unit test.




                                         3
The Development Cycle




          4
Benefits


The first goal is to make the test pass.

Subsequent users have a greater level of trust in the code.

Executable Documentation.




                                     5
Limitations


Some Code is Hard to Test.

Don’t Test That Code, Minimize that Code.

Put the important code in a library and test that code.




                                    6
Limitations


Management support is essential.

Without the organization support, that TDD is going to improve the
product.

Management will feel that time spent writing tests is wasted.




                                   7
Limitations



Badly written tests, are expensive to maintain.




                                    8
Limitations
The level of coverage and testing detail achieved during repeated TDD
cycles cannot easily be re-created at a later date.

Therefore these original tests become increasingly precious as time goes
by.

If a poor architecture, a poor design or a poor testing strategy leads to a
late change that makes dozens of existing tests fail, it is important that
they are individually fixed.

Merely deleting, disabling or rashly altering them can lead to un-
detectable holes in the test coverage.

                                     9
Limitations

Unexpected gaps in test coverage may exist or occur for a number of
reasons.

  One or more developers in a team was not so committed to the TDD
  strategy and did not write tests properly.

  Some sets of tests have been invalidated, deleted or disabled
  accidentally or on purpose during later work.

  Alterations may be made that result in no test failures when in fact bugs
  are being introduced and remaining undetected.


                                   10
Limitations


Unit tests created in a TDD environment are typically created by the
developer who will also write the code that is being tested.

  The tests may therefore share the same blind spots with the code.




                                  11
Limitations



The high number of passing unit tests may bring a false sense of security




                                   12
Unit Tests



A unit is the smallest testable part of an application.




                                     13
Unit Tests

 1   <?php
 2   class WhenTestingAdder {
 3       public function shouldAddValues() {
 4           $adder = new Adder();
 5           $this->assertEquals(2,     $adder->add(1, 1));
 6           $this->assertEquals(3,     $adder->add(1, 2));
 7           $this->assertEquals(4,     $adder->add(2, 2));
 8           $this->assertEquals(0,     $adder->add(0, 0));
 9           $this->assertEquals(-3,    $adder->add(-1, -2));
10           $this->assertEquals(0,     $adder->add(-1, 1));
11           $this->assertEquals(2222, $adder->add(1234, 988));
12       }
13   }
14   ?>




                                 14
Integration Tests



Individual software modules are combined and tested as a group.

It occurs after unit testing and before system testing.




                                    15
System Tests


Testing conducted on a complete, integrated system to evaluate the
system’s compliance with its specified requirements.

Falls within the scope of black box testing, and as such, should require no
knowledge of the inner design of the code or logic.




                                   16
Ok Now What?


No enhancements without defined requirements.

  Can not write tests for items without requirements.




                                  17
Examples



HelloWorld

TicTacToe




                18
Q&A




 19
Links
PHPUnit

   http://www.phpunit.de/

Three Rules of TDD

   http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd

TDD - Wikipedia

   http://en.wikipedia.org/wiki/Test-driven_development

BDD - Wikipedia

   http://en.wikipedia.org/wiki/Behavior_Driven_Development

http://www.phpspec.org/

                                          20

More Related Content

What's hot

Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
Pascal Larocque
 
Tdd com Java
Tdd com JavaTdd com Java
Tdd com Java
Rafael Miceli
 
TDD with RSpec
TDD with RSpecTDD with RSpec
TDD with RSpec
Rachid Calazans
 
Tdd
TddTdd
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
bhochhi
 
TDD = bra design?
TDD = bra design?TDD = bra design?
TDD = bra design?
Kjetil Klaussen
 
Python and test
Python and testPython and test
Python and test
Micron Technology
 
Test drive on driven development process
Test drive on driven development processTest drive on driven development process
Test drive on driven development process
Muralidharan Deenathayalan
 
Qa mockup interview for automation testing
Qa mockup interview for automation testingQa mockup interview for automation testing
Qa mockup interview for automation testing
KadharBashaJ
 
Automation frameworks
Automation frameworksAutomation frameworks
Automation frameworks
Vishwanath KC
 
fundamentals of testing (Fundamental of testing what)
fundamentals of testing (Fundamental of testing what)fundamentals of testing (Fundamental of testing what)
fundamentals of testing (Fundamental of testing what)
diana fitri, S.Kom
 
Fundamental of testing (what is testing)
Fundamental of testing (what is testing)Fundamental of testing (what is testing)
Fundamental of testing (what is testing)
helfa safitri
 
PHPUnit - Unit testing
PHPUnit - Unit testingPHPUnit - Unit testing
PHPUnit - Unit testing
Nguyễn Đào Thiên Thư
 
Tlc
TlcTlc
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Consulthinkspa
 
Automation testing interview pdf org
Automation testing interview pdf orgAutomation testing interview pdf org
Automation testing interview pdf org
Testbytes
 
UNIT TESTING
UNIT TESTINGUNIT TESTING
UNIT TESTING
Marius Crisan
 
Testing concurrent java programs - Sameer Arora
Testing concurrent java programs - Sameer AroraTesting concurrent java programs - Sameer Arora
Testing concurrent java programs - Sameer Arora
IndicThreads
 
Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test Presentation
Sayedur Rahman
 
Test Driven Development Powered by LEGO
Test Driven Development Powered by LEGOTest Driven Development Powered by LEGO
Test Driven Development Powered by LEGO
Agile Montréal
 

What's hot (20)

Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
 
Tdd com Java
Tdd com JavaTdd com Java
Tdd com Java
 
TDD with RSpec
TDD with RSpecTDD with RSpec
TDD with RSpec
 
Tdd
TddTdd
Tdd
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD = bra design?
TDD = bra design?TDD = bra design?
TDD = bra design?
 
Python and test
Python and testPython and test
Python and test
 
Test drive on driven development process
Test drive on driven development processTest drive on driven development process
Test drive on driven development process
 
Qa mockup interview for automation testing
Qa mockup interview for automation testingQa mockup interview for automation testing
Qa mockup interview for automation testing
 
Automation frameworks
Automation frameworksAutomation frameworks
Automation frameworks
 
fundamentals of testing (Fundamental of testing what)
fundamentals of testing (Fundamental of testing what)fundamentals of testing (Fundamental of testing what)
fundamentals of testing (Fundamental of testing what)
 
Fundamental of testing (what is testing)
Fundamental of testing (what is testing)Fundamental of testing (what is testing)
Fundamental of testing (what is testing)
 
PHPUnit - Unit testing
PHPUnit - Unit testingPHPUnit - Unit testing
PHPUnit - Unit testing
 
Tlc
TlcTlc
Tlc
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Automation testing interview pdf org
Automation testing interview pdf orgAutomation testing interview pdf org
Automation testing interview pdf org
 
UNIT TESTING
UNIT TESTINGUNIT TESTING
UNIT TESTING
 
Testing concurrent java programs - Sameer Arora
Testing concurrent java programs - Sameer AroraTesting concurrent java programs - Sameer Arora
Testing concurrent java programs - Sameer Arora
 
Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test Presentation
 
Test Driven Development Powered by LEGO
Test Driven Development Powered by LEGOTest Driven Development Powered by LEGO
Test Driven Development Powered by LEGO
 

Viewers also liked

Scott's PorchLights Speech Slides
Scott's PorchLights Speech SlidesScott's PorchLights Speech Slides
Scott's PorchLights Speech Slides
Scott Abbott
 
BVSNInternal Cesna Awards 2009 10 06
BVSNInternal Cesna Awards 2009 10 06BVSNInternal Cesna Awards 2009 10 06
BVSNInternal Cesna Awards 2009 10 06
NTUEE79
 
Huraian sukatan kh thun 6
Huraian sukatan kh thun 6Huraian sukatan kh thun 6
Hubris
HubrisHubris
Hubris
mwotton
 
Porch Lights Speech Slides 2010
Porch Lights Speech Slides 2010Porch Lights Speech Slides 2010
Porch Lights Speech Slides 2010
Scott Abbott
 

Viewers also liked (7)

Scott's PorchLights Speech Slides
Scott's PorchLights Speech SlidesScott's PorchLights Speech Slides
Scott's PorchLights Speech Slides
 
Huraian sukatan kh thun 4
Huraian sukatan kh thun 4Huraian sukatan kh thun 4
Huraian sukatan kh thun 4
 
BVSNInternal Cesna Awards 2009 10 06
BVSNInternal Cesna Awards 2009 10 06BVSNInternal Cesna Awards 2009 10 06
BVSNInternal Cesna Awards 2009 10 06
 
Huraian sukatan kh thun 6
Huraian sukatan kh thun 6Huraian sukatan kh thun 6
Huraian sukatan kh thun 6
 
Huraian sukatan kh thun 5
Huraian sukatan kh thun 5Huraian sukatan kh thun 5
Huraian sukatan kh thun 5
 
Hubris
HubrisHubris
Hubris
 
Porch Lights Speech Slides 2010
Porch Lights Speech Slides 2010Porch Lights Speech Slides 2010
Porch Lights Speech Slides 2010
 

Similar to Test Driven Development

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Kumaresh Chandra Baruri
 
xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012
Justin Gordon
 
TestDrivenDeveloment
TestDrivenDevelomentTestDrivenDeveloment
TestDrivenDeveloment
Antonio Tapper
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
ikhwanhayat
 
Test driven development
Test driven developmentTest driven development
Test driven development
Fraboni Ec
 
Test driven development
Test driven developmentTest driven development
Test driven development
Harry Potter
 
Test driven development
Test driven developmentTest driven development
Test driven development
Luis Goldster
 
Test driven development
Test driven developmentTest driven development
Test driven development
Tony Nguyen
 
Test driven development
Test driven developmentTest driven development
Test driven development
Young Alista
 
Test driven development
Test driven developmentTest driven development
Test driven development
James Wong
 
Test driven development
Test driven developmentTest driven development
Test driven development
lukaszkujawa
 
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd   seven years afterIan Cooper webinar for DDD Iran: Kent beck style tdd   seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
Iranian Domain-Driven Design Community
 
Test driven development
Test driven developmentTest driven development
Test driven development
Sunil Prasad
 
Cleaner Code Through Test-Driven Development
Cleaner Code Through Test-Driven DevelopmentCleaner Code Through Test-Driven Development
Cleaner Code Through Test-Driven Development
All Things Open
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
harinderpisces
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
adrianmitev
 
Android tdd
Android tddAndroid tdd
Android tdd
Nhan Cao
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
Seapine Software
 
Test Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionTest Driven Development - Overview and Adoption
Test Driven Development - Overview and Adoption
Pyxis Technologies
 
Test driven development
Test driven developmentTest driven development
Test driven development
Nascenia IT
 

Similar to Test Driven Development (20)

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012
 
TestDrivenDeveloment
TestDrivenDevelomentTestDrivenDeveloment
TestDrivenDeveloment
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
 
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 development
Test driven developmentTest driven development
Test driven development
 
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd   seven years afterIan Cooper webinar for DDD Iran: Kent beck style tdd   seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Cleaner Code Through Test-Driven Development
Cleaner Code Through Test-Driven DevelopmentCleaner Code Through Test-Driven Development
Cleaner Code Through Test-Driven Development
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Android tdd
Android tddAndroid tdd
Android tdd
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
 
Test Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionTest Driven Development - Overview and Adoption
Test Driven Development - Overview and Adoption
 
Test driven development
Test driven developmentTest driven development
Test driven development
 

More from Jason Ragsdale

Tulsa techfest2010 security
Tulsa techfest2010   securityTulsa techfest2010   security
Tulsa techfest2010 security
Jason Ragsdale
 
Tulsa tech fest 2010 - web speed and scalability
Tulsa tech fest 2010  - web speed and scalabilityTulsa tech fest 2010  - web speed and scalability
Tulsa tech fest 2010 - web speed and scalability
Jason Ragsdale
 
Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010
Jason Ragsdale
 
RIA with Flex & PHP - Tulsa TechFest 2009
RIA with Flex & PHP  - Tulsa TechFest 2009RIA with Flex & PHP  - Tulsa TechFest 2009
RIA with Flex & PHP - Tulsa TechFest 2009
Jason Ragsdale
 
Test Driven Development - Tulsa TechFest 2009
Test Driven Development - Tulsa TechFest 2009Test Driven Development - Tulsa TechFest 2009
Test Driven Development - Tulsa TechFest 2009
Jason Ragsdale
 
Test Driven Development - 09/2009
Test Driven Development - 09/2009Test Driven Development - 09/2009
Test Driven Development - 09/2009
Jason Ragsdale
 
What Is Security
What Is SecurityWhat Is Security
What Is Security
Jason Ragsdale
 
Yii Framework
Yii FrameworkYii Framework
Yii Framework
Jason Ragsdale
 
Web Speed And Scalability
Web Speed And ScalabilityWeb Speed And Scalability
Web Speed And Scalability
Jason Ragsdale
 
Yii Introduction
Yii IntroductionYii Introduction
Yii Introduction
Jason Ragsdale
 

More from Jason Ragsdale (10)

Tulsa techfest2010 security
Tulsa techfest2010   securityTulsa techfest2010   security
Tulsa techfest2010 security
 
Tulsa tech fest 2010 - web speed and scalability
Tulsa tech fest 2010  - web speed and scalabilityTulsa tech fest 2010  - web speed and scalability
Tulsa tech fest 2010 - web speed and scalability
 
Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010
 
RIA with Flex & PHP - Tulsa TechFest 2009
RIA with Flex & PHP  - Tulsa TechFest 2009RIA with Flex & PHP  - Tulsa TechFest 2009
RIA with Flex & PHP - Tulsa TechFest 2009
 
Test Driven Development - Tulsa TechFest 2009
Test Driven Development - Tulsa TechFest 2009Test Driven Development - Tulsa TechFest 2009
Test Driven Development - Tulsa TechFest 2009
 
Test Driven Development - 09/2009
Test Driven Development - 09/2009Test Driven Development - 09/2009
Test Driven Development - 09/2009
 
What Is Security
What Is SecurityWhat Is Security
What Is Security
 
Yii Framework
Yii FrameworkYii Framework
Yii Framework
 
Web Speed And Scalability
Web Speed And ScalabilityWeb Speed And Scalability
Web Speed And Scalability
 
Yii Introduction
Yii IntroductionYii Introduction
Yii Introduction
 

Recently uploaded

Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
GDSC PJATK
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
saastr
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 

Recently uploaded (20)

Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 

Test Driven Development

  • 1. TEST DRIVEN DEVELOPMENT DPUG - 09/08/2009 - Jason Ragsdale 1
  • 2. What is TDD? Test-driven development (TDD) is a software development technique that relies on the repetition of a very short development cycle: 1. First write a failing automated test case that defines a desired improvement or new function 2. Then produce code to pass that test 3. Finally refactor the new code to acceptable standards. 2
  • 3. The Three Laws of TDD 1. Don’t write any code unless it is to make a failing test pass. 2. Don’t write any more of a unit test than is sufficient to fail. 3. Don’t write more code than is sufficient to pass the one failing unit test. 3
  • 5. Benefits The first goal is to make the test pass. Subsequent users have a greater level of trust in the code. Executable Documentation. 5
  • 6. Limitations Some Code is Hard to Test. Don’t Test That Code, Minimize that Code. Put the important code in a library and test that code. 6
  • 7. Limitations Management support is essential. Without the organization support, that TDD is going to improve the product. Management will feel that time spent writing tests is wasted. 7
  • 8. Limitations Badly written tests, are expensive to maintain. 8
  • 9. Limitations The level of coverage and testing detail achieved during repeated TDD cycles cannot easily be re-created at a later date. Therefore these original tests become increasingly precious as time goes by. If a poor architecture, a poor design or a poor testing strategy leads to a late change that makes dozens of existing tests fail, it is important that they are individually fixed. Merely deleting, disabling or rashly altering them can lead to un- detectable holes in the test coverage. 9
  • 10. Limitations Unexpected gaps in test coverage may exist or occur for a number of reasons. One or more developers in a team was not so committed to the TDD strategy and did not write tests properly. Some sets of tests have been invalidated, deleted or disabled accidentally or on purpose during later work. Alterations may be made that result in no test failures when in fact bugs are being introduced and remaining undetected. 10
  • 11. Limitations Unit tests created in a TDD environment are typically created by the developer who will also write the code that is being tested. The tests may therefore share the same blind spots with the code. 11
  • 12. Limitations The high number of passing unit tests may bring a false sense of security 12
  • 13. Unit Tests A unit is the smallest testable part of an application. 13
  • 14. Unit Tests 1 <?php 2 class WhenTestingAdder { 3 public function shouldAddValues() { 4 $adder = new Adder(); 5 $this->assertEquals(2, $adder->add(1, 1)); 6 $this->assertEquals(3, $adder->add(1, 2)); 7 $this->assertEquals(4, $adder->add(2, 2)); 8 $this->assertEquals(0, $adder->add(0, 0)); 9 $this->assertEquals(-3, $adder->add(-1, -2)); 10 $this->assertEquals(0, $adder->add(-1, 1)); 11 $this->assertEquals(2222, $adder->add(1234, 988)); 12 } 13 } 14 ?> 14
  • 15. Integration Tests Individual software modules are combined and tested as a group. It occurs after unit testing and before system testing. 15
  • 16. System Tests Testing conducted on a complete, integrated system to evaluate the system’s compliance with its specified requirements. Falls within the scope of black box testing, and as such, should require no knowledge of the inner design of the code or logic. 16
  • 17. Ok Now What? No enhancements without defined requirements. Can not write tests for items without requirements. 17
  • 20. Links PHPUnit http://www.phpunit.de/ Three Rules of TDD http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd TDD - Wikipedia http://en.wikipedia.org/wiki/Test-driven_development BDD - Wikipedia http://en.wikipedia.org/wiki/Behavior_Driven_Development http://www.phpspec.org/ 20

Editor's Notes

  1. TDD is difficult to use in situations where full functional tests are required to determine success or failure. Examples of these are user interfaces, programs that work with databases, and some that depend on specific network configurations. TDD encourages developers to put the minimum amount of code into such modules and to maximise the logic that is in testable library code, using fakes and mocks to represent the outside world. Management support is essential. Without the entire organization believing that TDD is going to improve the product, management will feel that time spent writing tests is wasted.
  2. The tests themselves become part of the maintenance overhead of a project. Badly written tests, for example ones that include hard-coded error strings or which are themselves prone to failure, are expensive to maintain. There is a risk that tests that regularly generate false failures will be ignored, so that when a real failure occurs it may not be detected. It is possible to write tests for low and easy maintenance, for example by the reuse of error strings, and this should be a goal during the &apos;Refactor&apos; phase described above. The level of coverage and testing detail achieved during repeated TDD cycles cannot easily be re-created at a later date. Therefore these original tests become increasingly precious as time goes by. If a poor architecture, a poor design or a poor testing strategy leads to a late change that makes dozens of existing tests fail, it is important that they are individually fixed. Merely deleting, disabling or rashly altering them can lead to un-detectable holes in the test coverage.
  3. DO NOT IGNORE/DISABLE FAILING TESTS
  4. Unexpected gaps in test coverage may exist or occur for a number of reasons. Perhaps one or more developers in a team was not so committed to the TDD strategy and did not write tests properly, perhaps some sets of tests have been invalidated, deleted or disabled accidentally or on purpose during later work. If this happens, the confidence that a large set of TDD tests lend to further fixes and refactorings will be actually be misplaced. Alterations may be made that result in no test failures when in fact bugs are being introduced and remaining undetected.
  5. If, for example, a developer does not realize that certain input parameters must be checked, most likely neither the test nor the code will verify these input parameters. If the developer misinterprets the requirements specification for the module being developed, both the tests and the code will be wrong.
  6. resulting in less additional Q.A. activities, such as integration testing and compliance testing.
  7. In procedural programming a unit may be an individual program, function, procedure, etc., while in object-oriented programming, the smallest unit is a class, which may belong to a base/super class, abstract class or derived/child class.
  8. Integration testing takes as its input modules that have been unit tested, groups them in larger aggregates, applies tests defined in an integration test plan to those aggregates, and delivers as its output the integrated system ready for system testing.
  9. Forces a requirements discussion before writin&amp;#x2019; a bunch of code that don&amp;#x2019;t make the customer happy