What is the cucumber-jvm equivalent of Cucumber.wants_to_quit?

后端 未结 3 1886
一向
一向 2021-01-28 05:01

I am writing tests using cucumber-jvm and I want the system to stop running tests on the first scenario that fails. I found example code written for Cucumber Ruby that does thi

相关标签:
3条回答
  • 2021-01-28 05:32

    The accepted answer for cucumber-jvm quit on first test failure using

    throw new IllegalStateException()
    

    doesn't work in my experience.

    Try the cucumber command line switch -y instead.

    I didn't find any hard documentation for -y, but it was suggested here and a developer in that conversation committed to implementing it. I've tested it and it works as expected.

    I have not found a cucumber-jvm version of Cucumber.wants_to_quit? but perhaps this will cover your use case.

    0 讨论(0)
  • 2021-01-28 05:33

    I could not find any way to do it natively with Cucumber-JVM, but you can always do this:

    static boolean prevScenarioFailed = false;
    
    @Before
    public void setup() throws Exception {
        if (prevScenarioFailed) {
            throw new IllegalStateException("Previous scenario failed!");
        }
        // rest of your setup
    }
    
    @After
    public void teardown(Scenario scenario) throws Exception {
        prevScenarioFailed = scenario.isFailed();
        // rest of your teardown
    }
    
    0 讨论(0)
  • 2021-01-28 05:38

    Creating cucumber hooks in the step definition file helps to stop the test after a scenario fails. This involves creating @Before and @After methods. Take a look at this example:

    @Before
      public void setUp() {
        if (prevScenarioFailed) {
          throw new IllegalStateException("Previous scenario failed!");
        }
    
    
      }
    
      @After()
      public void stopExecutionAfterFailure(Scenario scenario) {
        prevScenarioFailed = scenario.isFailed();
      }
    
    0 讨论(0)
提交回复
热议问题