是否有可能使用 Rspec 涵盖大型 Rails 应用程序的所有方法?
我有一个应用程序,其中至少有 50-55 个模型,每个模型平均有 15 个方法。
是否可能&使用 rspec & 覆盖所有方法(包括非常复杂的方法)是否有意义?冠状病毒?
我还有以下疑问
Rspec 对控制器、助手和控制器是否也有用?意见?还是黄瓜,应该更有用吧?
rspec 会帮助我减少冗余吗?如果是,如何?
rspec 对于持续需求变化的应用程序有用吗?
I have an application which having at least 50-55 models with on an average 15 methods each.
Is it possible & is it make sense to cover all the methods (including very complex methods) using rspec & rcov ?
I also have following queries
Is Rspec also useful for the Controllers, helpers & views? Or cucumber, shoulda are more useful?
Will rspec help me to reduce redundancy?If yes, how?
will rspec is useful for continuous requirement changing applications?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然可以用测试覆盖所有方法,如果您之前先编写测试,则更是如此,从长远来看,这通常会导致应用程序更精简。另一方面,100% 的测试覆盖率并不能确保您的应用程序代码质量更好,或者您的团队更有生产力。它唯一可以确保的是你的应用程序有更少的缺陷,并且在重构的情况下不会破坏任何东西,然后出现了反对用测试覆盖所有方法的论点:
通常你会重构和维护代码,这通常涉及添加新方法和删除其他方法。
我想说,最好对其他对象或视图、控制器、助手等调用的所有公共方法进行测试,并测试所有相关的 API 方法,但没有必要测试每个方法。
另一方面,它将更多地取决于您的应用程序本身,而不是关于它的抽象对话。
你必须问自己这是否值得,它会增加什么价值等等,如果有意义,那就去做吧。无论您选择使用纯 rspec,还是使用 cucumber、shoulda、capybara 等
It certainly is possible to cover all methods with tests, even more if you start by writing the tests before, which usually lead to a leaner application on the long run. On the other hand having a 100% test coverage does not ensure that your application code quality is better or that your team is more productive. The only thing it might ensure is that your application has less flaws and that you won't break anything in case of refactoring, and then comes the argument against covering all methods with tests:
More often than not you'll be refactoring and maintaining code, which usually involves adding new methods and getting rid of other methods.
I'd say that it's good to have tests for all public methods called by other objects or views, controllers, helpers, etc. And test for all the relevant API methods, but it's far from necessary to have every single method tested.
On the other hand it will depend on your application itself more than on an abstract conversation about it.
You'd have to ask yourself if it's worth it, what value does it add, etc, and if it makes sense, go for it. Whether you choose to do it in pure rspec, or use cucumber, shoulda, capybara, etc