5

我最近了解到,Rspec + Capybara(我是测试事物的新手)。我一直在测试我创建的一些新模型。现在,我正在考虑将title列添加到我的Post模型中。这不是一项艰巨的任务,而且我以前做过很多次。但我意识到更新规范文件(例如帖子、帖子页面、用户、用户页面、工厂、sample_data 等)需要我做一些工作。

在这种情况下进行测试是浪费时间吗?或者绝对测试所有内容是一个好习惯?

我还想知道测试宝石是否也是浪费时间?因为他们可能已经被他们的创建者测试过(测试来自可靠教程的东西也是如此)。

4

2 回答 2

4

While the ruby community is known by its focus on testing, every case should be analyzed in context to figure out what the most cost-effective decisions are.

It is useful to think of tests as a technique to manage risk. If you don't think that displaying titles/adding them to the database is a task that is error-prone, complex to perform, or that the cost of adding those tests is higher than the risk of eventually breaking something, them it might be wise to not do it.

That said, since you said that you are new to testing, I would recommend (if you are not time-constrained, of course) to try to take the idea to the extreme of testing absolutely everything, so that you can have an idea of how much of it adds value, and how much is waste of time.

You might want to take a look at this blog post from DHH, the creator of Rails, where he talks about that: Testing like the TSA

About testing gems, it is generally well-accepted that they shouldn't be tested by your application tests, but by their creators. Most of the time you can simply assume that they work the ways they promise.

于 2012-11-10T02:13:21.713 回答
1

测试的主要概念之一是:“不可能测试一切”

于 2012-11-10T02:21:48.770 回答