您对控制器进行了多少测试?
我目前正在开始使用 BDD - 我之前没有编写过任何测试。 我总是尽量让我的模型保持胖而控制器瘦。
您认为控制器规格是否必要?
此致
I am currently beginning with BDD - I have not written any tests before.
I always try to keep my models fat and my controllers skinny.
What do you think - are controller specs necessary?
Best regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的。测试是否进行了正确的调用,以及是否在必要时进行了正确的重定向,并测试是否正在呈现正确的页面。因此,请测试您的应用程序是否按预期运行。
Yes. Test the correct calls are being made, and that the correct redirects and being made when necessary, and test that the correct pages are being rendered. So test that your application behaves as expected.
就我自己而言,我试图理解在测试中寻求高水平的代码覆盖率与维护一组可能相当脆弱的测试的长期成本之间的平衡。
假设我们有一个控制器,它的
初步想法是,三个计数情况(0、1、很多)的测试可能比例外情况的测试价值更低,并且更容易发生变化。价值较低,因为 a)。其他测试将发现页面显示中的问题 b)。测试非常接近于简单地复制代码。
如果开发人员错误地选择了 X,他的测试也会出错!如果 UI 的可用性测试表明 Y 是更好的显示页面,那么我们会同时更新代码和测试。测试真的取得了什么成果吗?
而异常情况在正常的 UI 测试中可能很难执行,而使用模拟测试确实很容易。而且,我们确实需要纠正异常后的行为。
For myself I'm trying to understand the balance between seeking high levels of code coverage in testing and the long term cost of maintaing a set of tests that may be quite brittle.
Suppose we have a Controller that goes
A tentative thought is is that tests of the three count cases (0, 1, many) may be less valuable, and more prone to change than the test of the exeption case. Less valuable because a). other testing will catch problems in page display b). the test gets very close to simply reproducing the code.
If the developer makes the wrong choice of X he gets the test wrong too! If usability testing of the UI reveals that Y is better page to display then we update the code and the test in tandem. Did the test really achieve anything?
Whereas the exception case may be very hard to exercise in normal UI testing, and really easy to test with mocks. And, behaviour following exceptions is something that we really do need to get right.
我认为如果将它们与良好的集成测试结合起来,它们就没有必要了。我发现应用程序的可用性非常重要,因此对于控制器/视图的每次更改,我都会单击应用程序并了解它的感觉。在我看来,为控制器和视图创建“哑”测试没有太多额外的价值。
对于集成测试,我使用 Cucumber。这使得测试整个堆栈成为可能,并确保您的应用程序按照您想要的方式执行。对于业务逻辑(胖模型),我仍然使用 RSpec。
I don't think they are necessary if you combine them with a good integration test. I find the usability of the application very important, so for every change in controller / views, I click through the application and find out how it feels. Creating 'dumb' tests for controllers and views doesn't have much extra value in my opinion.
For integration testing I'm using Cucumber. This makes it possible to test the full stack and make sure your application performs in the way you want. For the business logic (the fat models) I still use RSpec.