I am developing my first project using test driven development. I am using Zend Framework and PHPUnit.

Currently my project is at 100% code coverage but I am not sure I understand in what order I am supposed to write my code.

Am I supposed to write my test FIRST with what my objects are expected to do, or write my objects and then test them?

I've been working on completing a controller/model and then writing a test for it but I am not sure if this is what TDD is about.

Any advice?

For example, I wrote my Auth plugin and my Auth controller and tested that they work properly in my browser; then I sat down to write the tests for them which proved that there were some logical errors in the code that did work in the browser.

1 Answer 1


Test first. TDD is also IOW called "test-first development".

What you have been working at is not TDD.

TDD is 1-2-3:

  1. Write a failing test.
  2. Make it pass (committing any sins and shortcuts during the way).
  3. Remove duplicities (logical, not just physical).

In shorter words this is also advertised as "make it fail / make it work / make it right".

More in Kent Beck's awesome book Test-Driven Development By Example.

  • 11
    +1 These three steps are also known as "Red-Green-Refactor".
    – Fenton
    Sep 19, 2012 at 8:53
  • 2
    Make it pass means: Write only so much code that It pass, not more! That's quite important.
    – ollins
    Sep 19, 2012 at 9:30
  • 2
    It used to be called Test-First Development, but that is misleading: it's not about writing your tests first, it's about letting your tests drive the design and development. Writing your tests first is simply a prerequisite for that – how can your tests drive you if they don't exist yet? But you can write your tests first and still not let them drive you, and then you are not doing TDD. Sep 19, 2012 at 10:08
  • 3
    @deltree erm... I disagree with every statement you made!
    – Froome
    Sep 19, 2012 at 13:43
  • 2
    except "code coverage != TDD" :p
    – Froome
    Sep 19, 2012 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.