关于单元测试,什么不测试? [英] What not to test when it comes to Unit Testing?

查看:103
本文介绍了关于单元测试,什么不测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在项目编写单元的哪些部分几乎或实际上不可能进行测试?数据访问? FTP?

In which parts of a project writing unit tests is nearly or really impossible? Data access? ftp?

如果对此问题有一个答案,那么%100的承保范围就是一个神话,不是吗?

If there is an answer to this question then %100 coverage is a myth, isn't it?

推荐答案

此处我发现了(通过没了迈克尔·费瑟斯(Michael Feathers)说可能是答案:

Here I found (via haacked something Michael Feathers says that can be an answer:

他说,

在以下情况下,测试不是单元测试:

A test is not a unit test if:

  • 它与数据库对话
  • 它通过网络进行通信
  • 它触及文件系统
  • 它不能与您的任何其他单元测试同时运行
  • 您必须对环境做一些特殊的事情(例如编辑配置文件)才能运行它.
  • It talks to the database
  • It communicates across the network
  • It touches the file system
  • It can't run at the same time as any of your other unit tests
  • You have to do special things to your environment (such as editing config files) to run it.

他在同一篇文章中再次添加:

Again in same article he adds:

通常,单元测试应该很小,它们测试一种方法或几种方法之间的相互作用.当您将数据库,套接字或文件系统访问权限拉入单元测试时,它们不再与那些方法有关.它们是关于您的代码与其他软件的集成.

Generally, unit tests are supposed to be small, they test a method or the interaction of a couple of methods. When you pull the database, sockets, or file system access into your unit tests, they are not really about those methods any more; they are about the integration of your code with that other software.

这篇关于关于单元测试,什么不测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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