Struts2动作-是否测试? [英] Struts2 action - test it or not?

查看:74
本文介绍了Struts2动作-是否测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究一个使用Struts2框架的项目.我们使用单独的组件来进行数据库访问,这已经过了良好的测试.同时,我们正在从事的项目有很多未经测试的动作.在大多数操作中,我们至少使用一个DB服务调用.因此,一方面,这些动作非常简单.我不确定-是否应该为此编写单元测试?

I'm currently working on one project, that uses Struts2 framework. We use separate component for DB accessing, which is well tested. At the same time, project, that we work on has a lot of Actions, that are not tested. In most of the actions we use at least one DB-service call. So on one hand these actions are pretty simple. I'm not sure - should unit tests be written for that or not?

我认为好的做法是始终编写单元测试,但是这些操作是如此简单,并且我现在正承受着来自管理方面的巨大压力.因此,关键是-让Struts2操作不进行单元测试吗?

I think that good practice is write unit tests always, but these actions are so simple and I'm under big pressure from management side right now. So, is it critical or not - to leave Struts2 actions without unit tests?

推荐答案

以下是编写单元测试的三个主要原因.

Here are the three main reasons for writing unit tests.

  • 它可以帮助您知道您的代码现在可以正常工作.
  • 当将来添加或更改功能时,它有助于保护您的代码免受回归错误的影响.
  • 如果您在编写代码之前先编写单元测试,那么它将以一种非常好的方式集中您的设计过程-阅读TDD,以了解更多有关这样做的好处.

因此,请问问自己,编写单元测试的这三个原因中的任何一个是否都适用于此.如果对所有三个问题的回答均为否",请考虑编写单元测试并将其保留在代码库中的成本.将此成本与可能的收益进行比较.对是否应该编写单元测试做出明智的决定,并准备为您的经理辩护该决定.

So ask yourself whether any of these three reasons for writing unit tests apply here. If the answer is "no" for all three questions, then consider the cost of writing the unit tests, and of keeping them in your code base. Compare this cost with the possible benefit. Make an intelligent decision about whether you should be writing unit tests, and be prepared to defend that decision to your manager.

但是不要怀有一个先入为主的观念,即对于每个课程,单元测试始终是好的".并且不要带有相反的概念-单元测试始终是不必要的".都不是.

But don't carry a preconceived notion that "unit tests are always good, for every class". And don't carry the opposite notion - that "unit tests are always unnecessary". Neither is true.

这篇关于Struts2动作-是否测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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