CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Is there a way to stop test execution when one test fails?

Open shamili12 opened this issue 7 years ago • 6 comments

What are you trying to achieve?

So, one of the test scenario fails due to 503(Service Unavailable error) error. But, other scenarios in the test file continue to run. Is there a way to stop the execution when any of the test step fails??

What do you get instead?

Tests continue to run on failure.

It would be great if we can stop the test execution on failure in order to debug and also prevent other tests from failing.

shamili12 avatar Mar 26 '19 22:03 shamili12

You could create your own hook https://codecept.io/hooks#event-listeners and on event.test.failed(test, error) manually kill the node process.

DevinWatson avatar Apr 01 '19 10:04 DevinWatson

@DevinWatson Thanks for the update. Currently, we use the above mentioned hook in order to have a better understanding on test failure. Our tests run in BrowserStack on scheduled time intervals, killing the node manually isn't possible. So, wanted to check is there any other alternative to stop tests.

shamili12 avatar Apr 01 '19 19:04 shamili12

maybe you can do nodejs functionality..

vitaly87 avatar Apr 10 '19 07:04 vitaly87

Codecept runs on top of Mocha test framework. Mocha has the bail option to stop testing after the first failure. https://mochajs.org/api/mocha

You just need to pass the bail option to Mocha via the codecept config file:

{
  tests: './*_test.js',
  timeout: 10000,
  output: '',
  helpers: {},
  mocha: { bail: true }
}

xt1 avatar Apr 10 '19 10:04 xt1

@xt1 do you think it is possible to bail after specific test case only? For example, if logging to application fails

AdamOakman avatar Apr 10 '19 11:04 AdamOakman

Thanks @xt1. Will try the bail option.

shamili12 avatar Apr 10 '19 16:04 shamili12