Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce configure abortSuiteOnFailure so that test suite can stop on first failure #2090

Closed
ptrthomas opened this issue Aug 17, 2022 · 12 comments
Assignees

Comments

@ptrthomas
Copy link
Member

has been requested a few times in the last 5 years, and makes sense to me. for example this stack overflow q: https://stackoverflow.com/q/73385367/143475

so the idea is to set a suite-level flag and check its state before commencing any scenario, that should do it

@ptrthomas ptrthomas added this to the 1.3.0 milestone Aug 17, 2022
@ptrthomas ptrthomas self-assigned this Aug 17, 2022
@ptrthomas
Copy link
Member Author

thinking aloud there should be logic and a setting to stop the entire suite on the first failure

@ptrthomas
Copy link
Member Author

  • thinking more, there is no need for karate.abortSuite()
  • we will introduce a new setting abortSuiteOnFailure - this should take care of most folks
  • and we already have a karate.fail() to do this programmatically if needed

@joelpramos
Copy link
Contributor

Could be interesting if there’s a way to force a certain feature to be the first one to run and then conditionally fail the entire suite?

I’m thinking a pre condition for the rest of the tests, almost a classic smoke test to ensure your environment is good to go.

I’m sure there are ways to achieve this programmatically but don’t think there’s a pure karate way

@ptrthomas
Copy link
Member Author

@joelpramos good point. I think the karate-way to do that would be a karate.callSingle() that can call karate.abortSuite() (maybe we need it after all)

@joelpramos
Copy link
Contributor

Could we lean in more into tags and having a @beforeSuite or something for the feature file?

or, assuming you meant a callSingle from karate-config, another JS option introduced at the end of that chain for this behaviour

the concept does sound useful and something I’ve seen done in shell scripts or in bit of hacky way

@ptrthomas
Copy link
Member Author

@joelpramos yes I meant calling karate.abortSuite() in karate-config.js

but I see where you are coming from. it can be argued that karate.callSingle() is confusing and a more "feature compatible" way of running something at the start of a suite is missing today

what I really am not looking forward to do is

  • figuring out how this extra stuff gets into the report
  • do we allow this routine to update global variables (I guess we already do that)

for now I propose we keep this simple and consider adding a beforeSuite('path/to/some.feature') method to the Runner.Builder API

@joelpramos
Copy link
Contributor

selfishly not my preference but that is the quickest easiest path which will work for most people

For your questions, my thoughts for future reference:

  • I'd let it sit in the report as just another Feature/Scenario being executed with no special treatment
  • Preference would be not to update global variables (to discourage using this as a workaround when someone wants to add stuff "before all other tests") but would just take the quickest path to get it implemented and if that's allowing global variable manipulation, why not. A note could be added with direction in the docs and if folks choose to disregard it's either their problem (unless to many questions and issues start being raised).

My first thoughts would literally be chaining this in the run() method of the Suite before executing the main set of Features

@joelpramos
Copy link
Contributor

Was looking into some sections today and the Runner.parallel() encapsulates the Suite instance.

When refactoring, do you mind making that accessible from the caller of Runner? The use case I was looking into was pretty much this thread but something more hacky (a quick and dirty) but struggled without the Suite access.

@ptrthomas
Copy link
Member Author

@joelpramos the suite is designed to be immutable, if you want the suite you can always do Results.getSuite() - but if you mean you want to set something, before the tests run - it has to be via some setting on the Runner.Builder

@joelpramos
Copy link
Contributor

joelpramos commented Sep 26, 2022

I was trying to do the goal of this issue but in a hacky way but unfortunately I had no way to access the futures. Maybe the Runner should provide access to runtime elements within the suite (at a first glance the futures, JobManager, the features - to obtain what the suite actually calculates - drivers, etc.).

@ptrthomas
Copy link
Member Author

@joelpramos yeah, maybe the Runner should return a Future. we don't yet do a build() method like everybody else, maybe that is the way to go

@ptrthomas ptrthomas changed the title introduce karate.abortSuite() signal for all tests to stop introduce configure abortSuiteOnFailure so that test suite can stop on first failure Oct 31, 2022
@ptrthomas
Copy link
Member Author

1.3.0 released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants