我正致力于将单元测试集成到我所在团队的开发过程中,有一些人对此持怀疑态度。有什么好方法可以让团队中持怀疑态度的开发人员相信单元测试的价值?在我的具体情况下,我们将在添加功能或修复错误时添加单元测试。不幸的是,我们的代码库并不容易进行测试。
当前回答
单元测试的全部意义在于使测试变得简单。这是自动的。“make test”就完成了。如果您面临的问题之一是难以测试代码,那么这就是使用单元测试的最佳理由。
其他回答
单元测试可以帮助您以更少的错误发布软件,同时降低总体开发成本。您可以点击链接阅读更多关于单元测试的好处
根据我的经验,在复杂的软件环境中,单元测试和集成测试是“必须的”。
为了说服团队中的开发人员编写单元测试,您可能需要考虑在开发环境中集成单元测试回归分析(例如,在您的日常构建过程中)。
一旦开发人员知道如果单元测试失败,他们就不必花那么多时间调试它来发现问题,他们就会更有动力去编写这些测试。
这里有一个工具可以提供这样的功能:
单元测试回归分析工具
使用单元测试套件,可以在保持其余功能不变的情况下对代码进行更改。这是一个很大的优势。当你完成新功能的编码时,你会使用单元测试套件和回归测试套件吗?
One of the best things about unit testing is that your code will become easier to test as you do it. Preexisting code created without tests is always a challenge because since they weren't meant to be unit-tested, it's not rare to have a high level of coupling between classes, hard-to-configure objects inside your class - like an e-mail sending service reference - and so on. But don't let this bring you down! You'll see that your overall code design will become better as you start to write unit-tests, and the more you test, the more confident you'll become on making even more changes to it without fear of breaking you application or introducing bugs.
There are several reasons to unit-test your code, but as time progresses, you'll find out that the time you save on testing is one of the best reasons to do it. In a system I've just delivered, I insisted on doing automated unit-testing in spite of the claims that I'd spend way more time doing the tests than I would by testing the system manually. With all my unit tests done, I run more than 400 test cases in less than 10 minutes, and every time I had to do a small change in the code, all it took me to be sure the code was still working without bugs was ten minutes. Can you imagine the time one would spend to run those 400+ test cases by hand?
当涉及到自动化测试——无论是单元测试还是验收测试——每个人都认为编写可以手动完成的代码是浪费精力,有时这是真的——如果你计划只运行一次测试的话。自动化测试最好的部分是,您可以毫不费力地运行它们几次,并且在第二次或第三次运行之后,您所浪费的时间和精力已经得到了补偿。
最后一个建议是,不仅要对代码进行单元测试,还要先进行测试(详见TDD和BDD)。
单元测试的一个好处是,它们可以作为说明代码行为方式的文档。好的测试有点像参考实现,团队成员可以通过查看它们来了解如何将他们的代码与您的代码集成。
推荐文章
- 如何单元测试Arduino代码?
- 单元测试无效方法?
- 在单元测试中模拟HttpClient
- 为什么visual studio 2012找不到我的测试?
- 无法找到testhost.dll。请发布测试项目并重试
- 我如何“休眠”Dart程序
- 使用Mockito的泛型“any()”方法
- 在Visual Studio 2017中未发现单元测试
- 什么是单元测试?
- Java:如何测试调用System.exit()的方法?
- 如何在ASP中使用ILogger进行单元测试。网络核心
- 如何在node.js模块中访问和测试内部(非导出)函数?
- 当你的应用程序有一个tests目录时,在Django中运行一个特定的测试用例
- Angular 2单元测试:找不到名称“describe”
- 如何断言两个列表包含相同的元素在Python?