Stop BDD test after 1st failure


I have a BDD test that fails, but carries on running. Im looking to stop the test as soon as it fails, does anyone know how to do this?


Its a bit hackish, but one of the things I’ve been doing is adding @tags to my feature files, one of which is @required. If any of my @required scenarios fail I skip the rests of the tests. This keeps me from hammering against a system when some precondition like creating a test user has failed.


import cucumber.api.Scenario
import org.junit.Assume

public void beforeScenario(Scenario scenario) throws Throwable {
	this.scenario = scenario

	if (internal.GlobalVariable.exists('cucumberRequiredFailed')) {
		if (wbgeneral.getGlobalVariable('cucumberRequiredFailed')==scenario.getUri()){
			Assume.assumeTrue("SKIP SCENARIO (prereq failed): " + scenario.getName(), false)
		} else {
			wbgeneral.addGlobalVariable('cucumberRequiredFailed', '')
	} }

public void afterScenario(Scenario scenario){
		if ((scenario.getSourceTagNames().contains('@required')) && (scenario.isFailed())){
		wbgeneral.addGlobalVariable('cucumberRequiredFailed', scenario.getUri())
	} }
1 Like