我为什么要这两个单元测试,通过(而不仅仅是网络测试)Web测试? [英] Why should I both Unit test AND Web test (instead of just web test)?

查看:113
本文介绍了我为什么要这两个单元测试,通过(而不仅仅是网络测试)Web测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在的位置是这样的:如果我彻底地(通过VS.NET'08测试工具和华廷在我的情况,也许)与code覆盖和广谱测试使用Web测试我的ASP.NET应用程序的数据,我应该没有必要写个人的单元测试,因为我的code将结合通过所有层UI进行测试。 code覆盖率将确保我打code的各功能块(或透露未使用code)和我可以提供,这将覆盖所有合理预期的条件的数据。

不过,如果你有不同的意见,我想知道:


  1. 什么的其他的利益不单元测试给予了证明的努力,包括在一个项目(记住,我反正做网络测试,所以在很多情况下,单元测试将覆盖code,网页测试已经覆盖)。


  2. 可以解释与concete例子详细说明您的原因是什么?我经常看见的响应,如那不是它的意思为或它促进了更高质量的 - 这真的没有解决实际的问题,我必须面对,这一点,我怎么能证明 - 用实实在在的成果 - 花更多的一次测试?



解决方案

  

code覆盖率将保证我的的功能完好code的


打的的意思是测试

只有做网站测试的问题是,它只是确保你的的的code,而且它的出现的是在一个正确的高水平。

仅仅因为您加载的页面,并没有崩溃,并不意味着它实际工作正常。这里有一些事情我已经遇到过网络测试所涵盖的code的100%,还没有完全错过了一些非常严重的错误,这些错误的单元测试不会有。


  1. 从高速缓存正确加载页面,但实际的数据库被攻破

  2. 页面加载从数据库中的每个项目,但只显示第一个 - 它似乎被罚款,即使它在生产中完全失败,因为它的时间太长

  3. 页面上显示一个寻找有效的号码,这实际上是错误的,但它没有拿起因为1000000容易误解为100000

  4. 页面巧合显示一个有效的数字 - 10x50的是一样的25x20,但有错

  5. 页面应该添加日志条目的数据库,但所以这是没有看到这对用户不可见的。

  6. 验证被绕过,使网络的实际测试工作,所以我们错过了在认证code一个明显的错误。

这是很容易想出这样的事情数百更多的例子。

您需要两个单元测试,以确保您的code实际上做什么是应该在较低水平做,然后功能/集成(这你调用Web)上那些顶级测试,以当证明那些小的单元测试,部分链接在一起,它实际工作。

My current position is this: if I thoroughly test my ASP.NET applications using web tests (in my case via the VS.NET'08 test tools and WatiN, maybe) with code coverage and a broad spectrum of data, I should have no need to write individual unit tests, because my code will be tested in conjunction with the UI through all layers. Code coverage will ensure I'm hitting every functional piece of code (or reveal unused code) and I can provide data that will cover all reasonably expected conditions.

However, if you have a different opinion, I'd like to know:

  1. What additional benefit does unit testing give that justifies the effort to include it in a project (keep in mind, I'm doing the web tests anyway, so in many cases, the unit tests would be covering code that web tests already cover).

  2. Can you explain your reasons in detail with concete examples? Too often I see responses like "that's not what it's meant for" or "it promotes higher quality" - which really doesn't address the practical question I have to face, which is, how can I justify - with tangible results - spending more time testing?

解决方案

Code coverage will ensure I'm hitting every functional piece of code

"Hit" does not mean "Testing"

The problem with only doing web-testing is that it only ensures that you hit the code, and that it appears to be correct at a high-level.

Just because you loaded the page, and it didn't crash, doesn't mean that it actually works correctly. Here are some things I've encountered where 'web tests' covered 100% of the code, yet completely missed some very serious bugs which unit testing would not have.

  1. The page loaded correctly from a cache, but the actual database was broken
  2. The page loaded every item from the database, but only displayed the first one - it appeared to be fine even though it failed completely in production because it took too long
  3. The page displayed a valid-looking number, which was actually wrong, but it wasn't picked up because 1000000 is easy to mistake for 100000
  4. The page displayed a valid number by coincidence - 10x50 is the same as 25x20, but one is WRONG
  5. The page was supposed to add a log entry to the database, but that's not visible to the user so it wasn't seen.
  6. Authentication was bypassed to make the web-tests actually work, so we missed a glaring bug in the authentication code.

It is easy to come up with hundreds more examples of things like this.

You need both unit tests to make sure that your code actually does what it is supposed to do at a low level, and then functional/integration (which you're calling web) tests on top of those, to prove that it actually works when all those small unit-tested-pieces are chained together.

这篇关于我为什么要这两个单元测试,通过(而不仅仅是网络测试)Web测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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