TDD优先原则 [英] TDD FIRST principle

查看:36
本文介绍了TDD优先原则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白如何不遵守 TDD FIRST 原则在下面的代码中.

I am not understanding how the TDD FIRST principle isn't being adhered to in the following code.

这些是我关于 FIRST 原则的笔记:

These are my notes about the FIRST principle:

  • 快速:快速运行(子集)测试(因为您将一直运行它们)
  • 独立:不依赖于其他测试,因此可以以任何顺序运行任何子集
  • 可重复:运行 N 次,得到相同的结果(帮助隔离错误并实现自动化)
  • 自检:测试可以自动检测是否通过(无需人工检查输出)
  • 及时:与被测代码大致同时编写(使用 TDD,先编写!)
  • 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 希望她的网站在每个月的第一个星期二有一个特殊的布局.她有以下控制器和测试代码:

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

没有遵循什么 FIRST 原则?

What FIRST principle is not being followed?

  1. 快速
  2. 独立
  3. 可重复
  4. 自我检查
  5. 及时

我不确定没有遵循哪个 FIRST 原则:

I'm not sure which FIRST principle is not being adhered to:

  • :代码看起来很快,因为它的测试并不复杂.
  • 独立:测试不依赖于其他测试.
  • 可重复:每次测试都会得到相同的结果.'special_index' 如果是星期二,'index' 如果不是星期二.
  • 自检:测试可以自动检测是否通过.
  • 及时:代码和测试代码同时出现在这里.
  • Fast: The code seems to be fast because there is nothing complex about its tests.
  • Independent: The test doesn't depend on other tests.
  • Repeatable: The test will get the same result every time. 'special_index' if it's Tuesday and 'index' if it's not Tuesday.
  • Self-checking: The test can automatically detect if it's passed.
  • Timely: Both the code and the test code are presented here at the same time.

我在测验中选择了及时,因为测试代码是在控制器代码之后呈现的.但是我问错了,回想起来,这不是一个好的选择.我不确定这里没有遵循哪个 FIRST 原则.

I chose Timely on the quiz because the test code was presented after the controller code. But I got the question wrong, and in retrospect, this wasn't a good choice. I'm not sure which FIRST principle isn't being followed here.

推荐答案

It's not Repeatable 因为不是每天都是星期二 :) 如果你在星期一运行这个测试,你会得到一个结果,如果你运行星期二,一个不同的.

It's not Repeatable as not everyday is Tuesday :) If you run this test on Monday you will get one result, if you run it on Tuesday, a different one.

这篇关于TDD优先原则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆