ruby 黄瓜测试实践
我有很多黄瓜特征文件,每个特征文件都包含很多场景。
当一起运行时,其中一些会失败。 当我运行每个测试文件时,它们都通过了。 我认为我的数据库在每个场景之后都没有正确清理。
确定导致此行为的原因的正确过程是什么?
I have many cucumber feature files, each consists of many scenarios.
When run together, some of them fails.
When I run each single test file, they passes.
I think my database is not correctly clean after each scenario.
What is the correct process to determine what is causing this behavior ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听上去你们的测试是相互依赖的。您应该尝试让每个单独测试执行该单独测试运行所需的设置。
设置部分应该在功能的“给定”部分中完成。
就我个人而言,为了防止功能变得冗长并使它们接近所编写的业务语言,我有时会添加进行设置所需的其他步骤并从功能文件中的步骤调用它们。
如果这对你有意义
By the sound of it your tests are depening upon one another. You should be trying to get each indervidual test to do what ever set up is required for that indervidual test to run.
The set up parts should be done during the "Given" part of your features.
Personally, to stop the features from becoming verbose and to keep them close to the business language that they where written in, i sometimes add additional steps that are required to do the setup and call them from the steps that are in the feature file.
If this makes sence to you
由于不同的原因和不同的时间,这种情况发生在我身上。
有时,在一个场景中调用存根或模拟会搞砸另一个场景,但只有当它们都运行时(每个单独都很好)。
我能够解决这些问题的唯一方法是在运行足够的测试以失败的同时进行调试。您可以将调试器行放在step_definitions中,或者将其作为步骤本身调用(当我调用调试器时),并将其与仅将“调试器”作为ruby代码的步骤定义相匹配。
This happens to me for different reasons and different times.
Sometimes its that a stub or mock is invoked in one scenario that screws up another, but only when they are both run (each is fine alone).
The only way I've been able to solve these is debugging while running enough tests to get a failure. You can drop the debugger line in step_definitions or call it as a step itself (When I call the debugger) and match that up to a step definition that just says 'debugger' as the ruby code.