Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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.

share|improve this answer
+1 These three steps are also known as "Red-Green-Refactor". – Sohnee Sep 19 '12 at 8:53
Make it pass means: Write only so much code that It pass, not more! That's quite important. – ollins Sep 19 '12 at 9:30
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. – Jörg W Mittag Sep 19 '12 at 10:08
@deltree erm... I disagree with every statement you made! – Froome Sep 19 '12 at 13:43
except "code coverage != TDD" :p – Froome Sep 19 '12 at 14:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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