views:

366

answers:

4

I believe I already know the answer, but I am not 100% sure, so just a quick question: What does Red/Green Testing actually mean?

I understand it as "Write your tests first, so that they all fail (= all red), then write your code and watch how each test turns green, and when all are green, you're fine".

I heard this in Scott's MVC Talk at Mix, so I do not know if this is an "official" term or if he just made it up. (Edit: Scott actually also explains it starting at 55:00 Minutes, and he made a good remark why he beleives in it)

A: 

if you're correct i don't like it, i wouldn't trust anyone (even the customer) to get all the necessary tests to be done when all 'green'. but I've never done TDD.

Dustin Getz
+5  A: 

It does refer to TDD or Test Driven Development, but it would apply to each test. Write the test first, then write the code to pass the test. It would be wrong to write ALL the tests first. TDD is an incremental development approach.

The basic idea is no code is written before there is failing test (RED). When you have a failing test, then you write the code to pass the test (GREEN). Now you are ready to write the next test -- i.e., no new tests until all are green. Or refactor, as @Brian points out.

tvanfosson
+3  A: 

"Red-Green-Refactor" is the TDD mantra.

http://en.wikipedia.org/wiki/Test-driven_development

When I'm on a sugar-rush after an afternoon indulgence in the office candy dish, I sometimes shout these words as I code. It's easier to write tests up front when you reward yourself after writing a failing test case by shouting "Red!" and eating a piece of chocolate. :)

Brian
+1 for remembering refactoring
tvanfosson
+2  A: 

When you run a TDD GUI, the display is red until all tests pass, then it switches to green.

This is a summary of the rough outline of test-first development.

  1. Write some skeleton code that compiles, has enough API to be testable.

  2. Write tests which -- initially -- will be mostly failures. Red.

  3. Finish the code. The tests pass. Green.

At this point, you at least have something that works. However, what you have is not very high quality. So you'll need to refactor to improve overall quality.

S.Lott