What is red/green testing?

前端 未结 3 670
鱼传尺愫
鱼传尺愫 2021-02-19 16:41

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 f

相关标签:
3条回答
  • 2021-02-19 16:50

    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.

    0 讨论(0)
  • 2021-02-19 16:55

    "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. :)

    0 讨论(0)
  • 2021-02-19 17:09

    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.

    0 讨论(0)
提交回复
热议问题