gpt4 book ai didi

tdd - TDD FIRST原则

转载 作者:行者123 更新时间:2023-12-03 10:39:06 24 4
gpt4 key购买 nike

我不明白下面的代码如何不遵守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?

  1. Fast
  2. Independent
  3. Repeatable
  4. Self-checking
  5. Timely


我不确定哪个FIRST原则没有得到遵守:
  • 快速:该代码似乎很快,因为其测试没有什么复杂的问题。
  • 独立:该测试不依赖于其他测试。
  • 可重复的:每次测试将获得相同的结果。如果是星期二,则为'special_index';如果不是星期二,则为'index'
  • 自检:测试可以自动检测是否通过。
  • 及时:此处同时显示代码和测试代码。

  • 我在测验中选择了 Timely ,因为测试代码在 Controller 代码之后出现。但是我把这个问题弄错了,回想起来,这不是一个好选择。我不确定这里没有遵循哪个第一原则。

    最佳答案

    这不是Repeatable,因为不是每天都在星期二:)如果在星期一运行此测试,则将得到一个结果,如果在星期二运行,则将得到另一个结果。

    关于tdd - TDD FIRST原则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18024785/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com