我正致力于将单元测试集成到我所在团队的开发过程中,有一些人对此持怀疑态度。有什么好方法可以让团队中持怀疑态度的开发人员相信单元测试的价值?在我的具体情况下,我们将在添加功能或修复错误时添加单元测试。不幸的是,我们的代码库并不容易进行测试。
当前回答
这是非常以. net为中心的,但是有人尝试过Pex吗?
我非常怀疑,直到我尝试了——哇,多么精彩的表演。以前我想“我不会被这个概念说服,直到我明白它实际上对我有什么好处”。我只跑了一次就改变了主意,说:“我不在乎你怎么知道那里有致命异常的风险,但现在我知道我必须处理它”
也许这种行为唯一的缺点是它会标记所有事情,给你六个月的积压。但是,如果你有代码债,你总是有代码债,只是你不知道而已。告诉项目经理可能有20万个故障点,而你之前只知道有几十个,这是一个令人讨厌的前景,这意味着首先解释这个概念是至关重要的。
其他回答
在我们的办公室里,每天都有这样的对话:
“伙计,我就是喜欢单元测试,我刚刚能够对某些东西的工作方式进行了一系列更改,然后能够通过再次运行测试来确认我没有破坏任何东西……”
细节每天都在变化,但情绪却不变。单元测试和测试驱动开发(TDD)有很多隐藏的和个人的好处,也有很多明显的好处,除非他们自己做,否则你无法真正向他们解释。
但是,忽略这一点,下面是我的尝试!
Unit Tests allows you to make big changes to code quickly. You know it works now because you've run the tests, when you make the changes you need to make, you need to get the tests working again. This saves hours. TDD helps you to realise when to stop coding. Your tests give you confidence that you've done enough for now and can stop tweaking and move on to the next thing. The tests and the code work together to achieve better code. Your code could be bad / buggy. Your TEST could be bad / buggy. In TDD you are banking on the chances of both being bad / buggy being low. Often it's the test that needs fixing but that's still a good outcome. TDD helps with coding constipation. When faced with a large and daunting piece of work ahead writing the tests will get you moving quickly. Unit Tests help you really understand the design of the code you are working on. Instead of writing code to do something, you are starting by outlining all the conditions you are subjecting the code to and what outputs you'd expect from that. Unit Tests give you instant visual feedback, we all like the feeling of all those green lights when we've done. It's very satisfying. It's also much easier to pick up where you left off after an interruption because you can see where you got to - that next red light that needs fixing. Contrary to popular belief unit testing does not mean writing twice as much code, or coding slower. It's faster and more robust than coding without tests once you've got the hang of it. Test code itself is usually relatively trivial and doesn't add a big overhead to what you're doing. This is one you'll only believe when you're doing it :) I think it was Fowler who said: "Imperfect tests, run frequently, are much better than perfect tests that are never written at all". I interpret this as giving me permission to write tests where I think they'll be most useful even if the rest of my code coverage is woefully incomplete. Good unit tests can help document and define what something is supposed to do Unit tests help with code re-use. Migrate both your code and your tests to your new project. Tweak the code till the tests run again.
我参与的很多工作都没有很好地进行单元测试(web应用程序用户交互等),但即使如此,我们在这个商店里都被测试感染了,当我们把测试束缚住时,我们最高兴。我怎么极力推荐这种方法都不为过。
当涉及到重构或重写一段代码时,单元测试也特别有用。如果您有良好的单元测试覆盖率,您就可以满怀信心地进行重构。如果没有单元测试,通常很难确保您没有破坏任何东西。
当您手动测试软件时,通常会使用一小组测试/操作。最终,您将自动修改输入数据或操作,以便围绕已知问题进行导航。应该有单元测试来提醒您某些事情不能正常工作。
我建议在编写代码之前编写测试,添加新的测试/数据来改进主代码的功能!
Unit Testing is one of the most adopted methodologies for high quality code. Its contribution to a more stable, independent and documented code is well proven . Unit test code is considered and handled as an a integral part of your repository, and as such requires development and maintenance. However, developers often encounter a situation where the resources invested in unit tests where not as fruitful as one would expect. In an ideal world every method we code will have a series of tests covering it’s code and validating it’s correctness. However, usually due to time limitations we either skip some tests or write poor quality ones. In such reality, while keeping in mind the amount of resources invested in unit testing development and maintenance, one must ask himself, given the available time, which code deserve testing the most? And from the existing tests, which tests are actually worth keeping and maintaining? See here
这是非常以. net为中心的,但是有人尝试过Pex吗?
我非常怀疑,直到我尝试了——哇,多么精彩的表演。以前我想“我不会被这个概念说服,直到我明白它实际上对我有什么好处”。我只跑了一次就改变了主意,说:“我不在乎你怎么知道那里有致命异常的风险,但现在我知道我必须处理它”
也许这种行为唯一的缺点是它会标记所有事情,给你六个月的积压。但是,如果你有代码债,你总是有代码债,只是你不知道而已。告诉项目经理可能有20万个故障点,而你之前只知道有几十个,这是一个令人讨厌的前景,这意味着首先解释这个概念是至关重要的。
推荐文章
- 如何单元测试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?