tdd - TDD FIRST原则

标签 tdd

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

    相关文章:

    python - 如何使用 Docker 容器作为 virtualenv 从 IDE 运行 Python 测试?

    python - 我应该如何指示尚未用 Python 编写测试?

    c# - 如何在 Xunit 中测试使用 List<List<T> 作为输入参数的方法

    c# - 如何在 fake it easy 中正确断言 MustHaveHappend(object)

    unit-testing - 如何说服团队中的程序员进行 TDD?

    testing - Elixir 测试 - ExUnit - 重复数据实例

    java - 它是测试驱动开发方法吗?

    带有测试驱动开发的 Javascript 编码指南

    unit-testing - 当基类被淘汰时,单元测试如何变化?

    xcode - 如何将 XCTest 标记为挂起?