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

PPT
How to become a testing expert
PPTX
Test driven development
PDF
TDD CrashCourse Part2: TDD
PPTX
PHPUnit - Unit testing
PDF
Tdd practices
PPTX
Test driven development(tdd)
How to become a testing expert
Test driven development
TDD CrashCourse Part2: TDD
PHPUnit - Unit testing
Tdd practices
Test driven development(tdd)

What's hot (19)

PDF
Test driven development - Zombie proof your code
KEY
TDD refresher
PDF
ZendCon Security
PPTX
TDD with RSpec
PPTX
TGT#16 - Sztuka projektowania testów - Agnieszka Garwolińska
PPTX
Tdd com Java
PPTX
Test-driven development & Behavior-driven development basics
PPTX
RESTful Microservices
PDF
Test driven development_continuous_integration
ODP
Tdd in php a brief example
PDF
Test Driven Development
PPTX
XP in the full stack
PPTX
Test management struggles and challenges in SDLC
ODP
Java code coverage with JCov. Implementation details and use cases.
PDF
Codeception Testing Framework -- English #phpkansai
PPTX
VT.NET 20160411: An Intro to Test Driven Development (TDD)
PPTX
REST API level TDD with NodeJS
PDF
Python and test
Test driven development - Zombie proof your code
TDD refresher
ZendCon Security
TDD with RSpec
TGT#16 - Sztuka projektowania testów - Agnieszka Garwolińska
Tdd com Java
Test-driven development & Behavior-driven development basics
RESTful Microservices
Test driven development_continuous_integration
Tdd in php a brief example
Test Driven Development
XP in the full stack
Test management struggles and challenges in SDLC
Java code coverage with JCov. Implementation details and use cases.
Codeception Testing Framework -- English #phpkansai
VT.NET 20160411: An Intro to Test Driven Development (TDD)
REST API level TDD with NodeJS
Python and test
Ad

Similar to Test Driven Development - 09/2009 (20)

PDF
Test Driven Development
PPTX
Test Driven Development
PPTX
Test Driven Development
ODP
xUnit and TDD: Why and How in Enterprise Software, August 2012
DOCX
TestDrivenDeveloment
PPTX
Test driven development
PPTX
Test driven development
PPTX
Test driven development
PPTX
Test driven development
PPTX
Test driven development
PPTX
Test driven development
PDF
Test driven development
PPTX
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
PPTX
Understanding Unit Testing
PPT
Test-Driven Development
PPTX
Test driven development
PPTX
TDD - Agile
PPTX
Android tdd
PPTX
Cleaner Code Through Test-Driven Development
PDF
Test-Driven Development Reference Card
Test Driven Development
Test Driven Development
Test Driven Development
xUnit and TDD: Why and How in Enterprise Software, August 2012
TestDrivenDeveloment
Test driven development
Test driven development
Test driven development
Test driven development
Test driven development
Test driven development
Test driven development
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
Understanding Unit Testing
Test-Driven Development
Test driven development
TDD - Agile
Android tdd
Cleaner Code Through Test-Driven Development
Test-Driven Development Reference Card
Ad

More from Jason Ragsdale (10)

PDF
Tulsa techfest2010 security
PDF
Tulsa tech fest 2010 - web speed and scalability
KEY
Caching: A Guided Tour - 10/12/2010
KEY
RIA with Flex & PHP - Tulsa TechFest 2009
KEY
Test Driven Development - Tulsa TechFest 2009
PDF
What Is Security
KEY
Yii Framework
PPT
Web Speed And Scalability
KEY
Yii Introduction
KEY
Test Driven Development
Tulsa techfest2010 security
Tulsa tech fest 2010 - web speed and scalability
Caching: A Guided Tour - 10/12/2010
RIA with Flex & PHP - Tulsa TechFest 2009
Test Driven Development - Tulsa TechFest 2009
What Is Security
Yii Framework
Web Speed And Scalability
Yii Introduction
Test Driven Development

Recently uploaded (20)

PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Cloud computing and distributed systems.
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
cuic standard and advanced reporting.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
KodekX | Application Modernization Development
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Machine learning based COVID-19 study performance prediction
PPTX
MYSQL Presentation for SQL database connectivity
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Cloud computing and distributed systems.
Review of recent advances in non-invasive hemoglobin estimation
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cuic standard and advanced reporting.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
KodekX | Application Modernization Development
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf
Programs and apps: productivity, graphics, security and other tools
Advanced methodologies resolving dimensionality complications for autism neur...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation theory and applications.pdf
Big Data Technologies - Introduction.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
The AUB Centre for AI in Media Proposal.docx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Machine learning based COVID-19 study performance prediction
MYSQL Presentation for SQL database connectivity

Test Driven Development - 09/2009

  • 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

  • #7: 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.
  • #9: 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.
  • #10: DO NOT IGNORE/DISABLE FAILING TESTS
  • #11: 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.
  • #12: 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.
  • #13: resulting in less additional Q.A. activities, such as integration testing and compliance testing.
  • #14: 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.
  • #16: 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.
  • #18: Forces a requirements discussion before writin&amp;#x2019; a bunch of code that don&amp;#x2019;t make the customer happy