什么是红/绿测试?测试

2023-09-06 10:04:10 作者:森离九°

我想我已经知道答案,但我不是100%肯定,所以只是一个快速的问题:什么是红/绿测试实际上意味着

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?

我把它理解为先写你的测试,让他们都失败了(=全红),然后再编写code和观看了每个测试变为绿色,当所有是绿色的,你没事

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

我听说这斯科特的MVC讲座在混合的,所以我不知道这是一个官方一词,或者如果他只是做起来。 (编辑:斯科特实际上也说明了它起始于55:00分钟,他取得了良好的话,为什么他beleives的话)

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. ( Scott actually also explains it starting at 55:00 Minutes, and he made a good remark why he beleives in it)

推荐答案

它是指TDD和测试驱动开发,但它也适用于每一个测试。首先编写测试,然后编写code通过测试。这将是第一个写的所有测试错误。 TDD是一个渐进发展的道路。

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.

其基本思想是没有code被写入之前有失败的测试(红色)。当你有一个失败的测试,那么你写的code通过测试(绿色)。现在,您可以编写下一个测试 - 也就是说,没有新的考验,直到所有的都是绿色。或者重构,如@布赖恩指出。

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.