分步执行后,黄瓜将停止执行 [英] Cucumber Stopping Execution after Time in Steps
问题描述
我的测试之一一直等到Then
步骤中发生事件.如果测试正常,则没有问题,但是如果测试失败(即未触发任何事件),则它会挂起.
One of my tests waits until an event happens in the Then
step. If the test works fine there is no issue but if the test is failing (i.e. no event is triggered) then it just hangs.
如何在Cucumber
中设置超时?
我知道JUnit
具有一个超时参数,您可以在 @Test annotation
,Cucumber
是否有类似内容?
I know JUnit
has a timeout parameter you can use in the @Test annotation
, is there something similar for Cucumber
?
推荐答案
Cucumber
遵循了JUnit
模式,并在其步骤注释中提供了 timeout
参数.这需要一个较长的值,用于指定毫秒数,如果该秒数未完成执行,则该秒数将失败.
Cucumber
has followed the JUnit
pattern and offers a timeout
parameter in its steps annotations. This takes a long value specifying the number of milliseconds after which the step is failed if it doesn't finish execution.
您可以按以下方式使用它:
You can use it as follows:
@Then(value = "^verify (\\d+) events sent$", timeout = 5000)
这也适用于其他步骤类型(例如Given
,When
).
This also works on the other step types (e.g. Given
, When
).
别忘了在步骤定义字符串之前添加value =
.
Don't forget to add value =
before the steps definition string.
这篇关于分步执行后,黄瓜将停止执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!