Cucumber场景下的if语句怎么做?
我的应用程序具有权限,并且当特定权限打开时不需要运行某些测试,而当打开相同权限时需要运行某些测试。
有办法做到这一点吗?或者我需要使用不同的框架吗?
My app has permissions, and certain tests need to not be run when a particular permission is on, and some tests need to be run when that same permission is on.
Is there a way to do this? or do I need to use a different framework?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Cucumber 中排除“测试”的标准方法是向它们添加一个标签来识别它们,然后在调用 Cucumber 时指定要包含/排除哪些标签。在您的示例中,您可以标记特定场景:
或标记整个功能:
或标记场景大纲中的某些示例:
现在,当您运行 Cucumber 时,您可以根据需要排除这些标记:
当权限打开且您想要时运行所有测试:
当权限关闭并且您想要排除需要它的测试时:
如果您确实提前不知道,我使用的另一种方法是将步骤标记为
待定
如果它不适用给定当前场景,例如这会将步骤标记为“待处理”,这实际上意味着“未完全实施”,这并不理想,特别是如果您有许多这样的步骤 - 很难确保其他未实施的步骤不会意外蔓延并被所有您故意标记为此类的人隐藏。
The standard way of excluding 'tests' in Cucumber is to add a tag to them to identify them, then when invoking Cucumber you specify which tags to include/exclude. In your example, you could tag a specific scenario:
Or tag the whole feature:
Or tag certain examples in a scenario outline:
Now, when you run Cucumber, you can exclude those tags if necessary:
When the permission is on and you want to run all tests:
When the permission is off and you want to exclude the tests that need it:
An alternative which I have used with mixed results, if you really don't know ahead of time, is to mark a step as
pending
if it doesn't apply given the current scenario, e.g.This will mark the step as 'pending' which really means 'not fully implemented', which isn't ideal, especially if you have many such steps - it can be difficult to ensure that other unimplemented steps don't accidentally creep in and get hidden by all the ones you've deliberately marked as such.
我们经常遇到类似的情况,我们有两种解决方案,
按照建议添加标签,或者
为不同的权限类型创建不同的场景:
We get a similar instance of this a lot, we have 2 solutions,
either tags as suggested, or
create different scenarios for different permission types:
或许可以使用标签。如果没有更多细节,很难说。
May be possible using tags. Difficult to say without more detail.