Test Driven Web Development

Document Sample
Test Driven Web Development Powered By Docstoc
					Test Driven Web Development

          Nirav Mehta

      Linux Bangalore 2004
                  Session Plan
●   Introduction to test driven development
●   Test driven development with PHP
●   How to cope up with test driven development
●   Experiences
Test driven development says:
 write test cases before code!
Test before code is actually great way
       to improve code quality
  You may ask how can we do test
driven development in a web project?
●   Very well suited for OO programming
●   Web testing available – forms, auth etc
●   Automated tests fit well for repeatitive tests
●   Manual testing otherwise
    –   UI
    –   Usability
    –   Compatibility
PHP has two good tools available:
 PEAR::PhpUnit and SimpleTest
SimpleTest is a set of classes that
 empower you to write, run and
    manage your test cases
            Here's a small sample
class CartTestCase extends UnitTestCase {

    function testAddToCart() {
    $cart = &new Cart();
    $result = $cart->add(1000, 1);
    $this->assertTrue($result, 'Item

 You can assert for true/false, data
types, equality, patterns and errors
You can also initialize or clean up the
test environment, raise errors, pass or
             fail tests etc
Let us write and run some simple test
  cases for our shopping cart now
Faking an object – mock objects and
           server stubs
It's easy to test web pages with simple
 pattern matching and link following
SimpleTest also allows handling
   simple form submissions
The first thing you need in your web
app is authentication, so you need a
     way to test and manage it.
Alright, this all sounds good.

     But does it really work?
Yes, test driven development really
      works, despite frictions
TDD also fits very well with an agile
   development methodology
Get on with test driven development
●   Linux Bangalore Team

●   Resources:
    –   http://www.lastcraft.com/simple_test.php
●   Contact Me:
    –   nirav@magnet-i.com