TDD BDD PHP - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

TDD BDD PHP

Description:

Functional Testing (We're not going there!) 'Popular' PHP Testing Frameworks: PHPUnit ... As such, PHP devs can easily get in 'over their heads. ... – PowerPoint PPT presentation

Number of Views:189
Avg rating:3.0/5.0
Slides: 27
Provided by: oink
Category:
Tags: bdd | php | tdd | goingover

less

Transcript and Presenter's Notes

Title: TDD BDD PHP


1
TDD - BDD - PHP
  • Bill Barnett
  • ltbilly_at_booksmartbilly.comgt
  • OINK-PUG January 2008

2
Who Am I?
  • OINK-PUG's Founder
  • Lead Systems Analyst - SCRIP-SAFE International
  • PHP programmer for profit Ruby for fun.
  • Bourbon Drinking, Hockey Playing, Former Marine
  • Epicurean Night Owl with a Conservative Streak

3
Who Are You?(Who? Who? Who? Who?)
  • Beginning to use PHP's advanced features.
  • Sleepless the night of a release.
  • Overworked the day after.
  • Looking for a better way.
  • With a certain probability, not named Jerry.
  • Not currently using TDD or BDD.

4
Idiocy
  • "Never underestimate the power of stupid people
    in large groups."
  • (calendar.despair.com)

5
PHP5
  • Released July 2004
  • Advanced Language Features
  • Constructors Destructors
  • Public, Protected, Private properties and
    methods
  • Interfaces Abstract classes
  • Static properties and methods
  • Final properties and methods

6
PHP5
  • Enhanced MySQL Support
  • Prepared Statements
  • Bound Input Output Parameters
  • Multi-Query Functions
  • SSL

7
PHP5
  • XML Rebuilt
  • W3 Compliant
  • Standardized in libxml2
  • Parse Alter with SimpleXML
  • Reworked DOM XSL Extensions

8
PHP5
  • And More...
  • SQLite Embedded
  • Reworked Error Handlers Exceptions
  • SOAP
  • Iterators

9
Cluelessness
  • "There are no stupid questions, but there are a
    LOT of inquisitive idiots."
  • (calendar.despair.com)

10
Traditional Approach
  • Waterfall Methodology (Sequential)
  • Requirements Gathering
  • Big design ("The Spec")
  • Coding ("Implementation")
  • Testing
  • Integration
  • Maintenance

11
Advanced Programming Methodologies
  • Iterative Shorten the feedback loop
  • Agile Software Development
  • eXtreme Programming (XP)
  • SCRUM
  • Test Driven Development
  • Behavior Driven Development

12
Test Driven Development
  • Kent Beck Ward Cunningham
  • Features begin life as tests
  • "Red, Green, Refactor"
  • Write a test watch it fail (Red)
  • Write some code watch it pass (Green)
  • Refactor Repeat

13
Test Driven Development
  • Unit Testing (xUnit)
  • Functional Testing (We're not going there!)
  • Popular PHP Testing Frameworks
  • PHPUnit
  • SimpleTest
  • lime

14
What makes a good framework?
  • Assertions
  • Test grouping or suites
  • Data providers or fixtures
  • Mocking

15
Lets code!
16
Meetings
  • "None of us is as dumb as all of us."
  • (calendar.despair.com)

17
Benefits of Unit Testing
  • As much about design as testing
  • Forms a basis for refactoring (think improvement
    AND extension)
  • Builds confidence and reduces stress
  • Can serve as a documentation source
  • Can help ensure minimum code is written

18
Testing Pitfalls
  • Test the application, not the framework.
  • How do you define a unit in testing?
  • How do I know Im testing enough?
  • Can I test too much?
  • What is the link between what is tested and how
    the application is supposed to work?

19
Behavior Driven Development
  • Intended to address a basic flaw in TDD
  • Focus on application behavior
  • Specifications as tests
  • Specification, not verification
  • Domain Specific Language
  • Sapir-Whorf

20
BDD Frameworks for PHP
  • PHPSpec
  • Extensions of PHPUnit and lime?
  • Thats all (for now) folks!

21
PHPSpec
  • Identify a valuable behavior you want to
    implement
  • Describe it in plain text in the form "it should
    ... ", i.e. a specification
  • Write one or more specs/examples for the "it
    should" components of your specification
  • Implement the behavior you've just described in
    the specification
  • Refactor the implemented code if needed
  • Return to Step 1

22
Lets code some more!
23
Adversity
  • "That which does not kill me simply postpones the
    inevitable."
  • (calendar.despair.com)

24
What Now?How do I start?
  • Got a bug? Write a test!
  • Test the 10. (10 of the code does 90 of the
    work.)
  • Comment function contents.
  • Uncomment and test logic branches.
  • Repeat for nested branches until done.
  • "Some tests" is better than "no tests."

25
Review
  • PHP is a FWWTBR among scripting languages.
  • As such, PHP devs can easily get in "over their
    heads."
  • TDD BDD can help you sleep better, will win you
    the respect of your peers, and get you dates.
  • TDD BDD are not widely accepted or used by PHP
    developers at any level.
  • YMMV.

"Force with which to be reckoned." (Props to my
mom, the English teacher.)
26
Questions?
  • Links
  • PHPUnit http//www.phpunit.de/pocket_guide/
  • SimpleTest http//simpletest.sourceforge.net/en/o
    verview.html
  • lime http//www.symfony-project.org/book/1_0/15-U
    nit-and-Functional-Testing
  • PHPSpec http//dev.phpspec.org/manual/en/index.ht
    ml
Write a Comment
User Comments (0)
About PowerShow.com