单元测试无用的项目类型 [英] Type of Projects where Unit Testing is useless

查看:34
本文介绍了单元测试无用的项目类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是否认为必须在任何情况下进行单元测试(和测试驱动开发),或者是否应该有一些例外.我最近一直在研究项目类型,我看不到单元测试如何有用或改进设计、代码质量等.一种类型的项目是 PDF 报告生成器,它采用聚合数据(已经计算和QAed) 并将其输出为 PDF 报告文件.另一种类型是使用 3rd 方 ORM 工具的直接 CRUD 应用程序.我可以看到有人如何为 CRUD 应用程序使用单元测试提出论点,但这是很多不必要且耗时的设置工作,例如停止对数据库的所有调用和模拟业务对象等.你需要知道数据库是否发生了什么事.那么什么时候应该使用或避免单元测试?

Do you believe that Unit Testing (and test driven development) must be done under any set of circumstances or should there be some exceptions. I've been working on the type of projects lately where I can't see how Unit Testing would be useful or improve design, quality of code, etc. One type of project is PDF reports generator which takes aggregate data (values already calculated and QAed) and outputs it to a PDF report file. Another type is straight-forward CRUD applications using 3rd party ORM tool. I can see how someone could make an argument for using Unit Testing for CRUD application, but it's a lot of unnecessary and time consuming setup work, like stabbing out all the calls to a database and mocking business objects, etc. when at the end all you need to know if something happened to the DB. So when one should use or avoid Unit Testing?

谢谢

推荐答案

这通常主要取决于进度限制以及您将如何处理代码.如果你写的是一次性的(很多人认为它不存在),我认为不需要单元测试.

It often depends mostly on schedule constraints and what are you going to do with the code. If you're writting one-offs(which many would argue aren't existing anyway) I think unit tests are not needed.

但是,如果您正在编写一个模块化软件,并且将来可能会重复使用或重构 - 单元测试非常有用.

However if you're writting a modular software that will be potentially re-used or re-factored in the future - unit tests are very helpful.

我经常发现它们的主要目的不是确定当前实现中的错误,而是确保在更改到达时不会引入错误.

I often find the main purpose of them not to determine bugs in current implementation but to insure that no bugs introduced when changes arrive.

这篇关于单元测试无用的项目类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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