黄瓜背景与挂钩前的对比
我正在尝试找出一种良好的实践方法,即何时应该使用“背景”而不是“之前”挂钩。
我浏览过网络,查看其他人的博客文章,但有很多重叠之处。
有什么意见什么时候使用其中一个,也许更重要的是,什么时候绝对不使用其中一个?
I'm trying to figure out a good practice approach of when I should use Background over a Before hook.
I've browsed around the web looking at other peoples blog post but there's so much over lap.
Any opinions when to use which, and perhaps more importantly, when definitely not to use one of them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对区分两者的看法归结为使用测试作为沟通。如果您添加的功能对于阅读简单语言场景和功能的任何人来说都是必要的,那么它应该放在背景部分中。如果该功能只是测试框架实现的一部分,那么它应该进入 Before 挂钩。
保持场景和功能清晰是构建良好的 Cucumber 测试的重要组成部分。
我想您可以使用的另一个心理检查是问自己是否有人正在手动测试您的场景,他们是否需要执行您想要放入后台/之前挂钩的功能。如果他们愿意,我会将其放在功能文件的背景部分中。如果他们不这样做,请将其放回到您的代码中。
My take on differentiating between the two comes down to using the tests as communication. If the functionality that you're adding is necessary for anyone reading the plain language Scenarios and features, it should go in the Background section. If the functionality is simply part of the implementation of your test framework, it should go into a Before hook.
Keeping the scenarios and features clear is an important part of building good Cucumber tests.
I guess another mental check you could use would be to ask yourself if someone was testing your scenarios manually, would they need to do the functionality that you want to put in the Background/before hook. If they would, I'd put it in the Background section in the feature file. If they wouldn't, put it in the hook back in your code.