我不明白下面的代码如何不遵守TDD FIRST principle。
这些是我关于FIRST原则的说明:
- Fast: run (subset of) tests quickly (since you'll be running them all the time)
- Independent: no tests depend on others, so can run any subset in any order
- Repeatable: run N times, get same result (to help isolate bugs and enable automation)
- Self-checking: test can automatically detect if passed (no human checking of output)
- Timely: written about the same time as code under test (with TDD, written first!)
测验问题:
Sally wants her website to have a special layout on the first Tuesday of every month. She has the following controller and test code:
# HomeController def index if Time.now.tuesday? render 'special_index' else render 'index' end end # HomeControllerSpec it "should render special template on Tuesdays" do get 'index' if Time.now.tuesday? response.should render_template('special_index') else response.should render_template('index') end end
What FIRST principle is not being followed?
- Fast
- Independent
- Repeatable
- Self-checking
- Timely
我不确定哪个FIRST原则没有得到遵守:
'special_index'
;如果不是星期二,则为'index'
。 我在测验中选择了 Timely ,因为测试代码在 Controller 代码之后出现。但是我把这个问题弄错了,回想起来,这不是一个好选择。我不确定这里没有遵循哪个第一原则。
最佳答案
这不是Repeatable
,因为不是每天都在星期二:)如果在星期一运行此测试,则将得到一个结果,如果在星期二运行,则将得到另一个结果。
关于tdd - TDD FIRST原则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18024785/