问题
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.
How can I set a timeout in Cucumber
?
I know JUnit
has a timeout parameter you can use in the @Test annotation, is there something similar for Cucumber
?
回答1:
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)
This also works on the other step types (e.g. Given
, When
).
Don't forget to add value =
before the steps definition string.
来源:https://stackoverflow.com/questions/47456589/cucumber-stopping-execution-after-time-in-steps