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

Hooks executed for Skipped Scenarios #2951

Open
joellis13 opened this issue Dec 5, 2024 · 1 comment
Open

Hooks executed for Skipped Scenarios #2951

joellis13 opened this issue Dec 5, 2024 · 1 comment

Comments

@joellis13
Copy link

joellis13 commented Dec 5, 2024

🤔 What's the problem you've observed?

When we have scenarios tagged with @Skip, Cucumber knows to "ignore" each step - even though it goes through the scenario and marks each step individually as "IGNORED." It is also executing all before/after hooks for skipped scenarios.

✨ Do you have a proposal for making it better?

If a whole scenario is skipped, under what circumstances would we want to execute the hooks or review each individual step in the scenario. It just takes more time and resources for no apparent value:

  • The before hook sets everything up for a scenario that doesn't run.
  • The review of each individual step provides no value - we know we're skipping it and it displays as such on the report (Serenity).
  • The after hooks runs and acts to close out a scenario that never ran. This ends up wasting time and resources, and often errs because it's trying to act on a scenario it's assuming has run.

Basically, if we tag a Scenario as @Skip, it should actually skip the whole scenario (or there should at least be an option for that). Test automation requires enough time and resources as is, we shouldn't be needlessly wasting more.

📚 Any additional context?

If there is a concept we're missing, please let us know. Most teams I know use the before hook for authorization or data setup, and the after for tear down and data restoration. If the scenario doesn't run, those aren't needed. Why would we want to run all that if we're skipping a scenario?

We know we can use "not @Skip" for tags and/or @ExcludeTags("Skip") in the Junit executor, but this completely disregards them, eliminating them from the report, which keeps them out of sight, out of mind, and we need our report to be able to call attention to skipped tests.

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Dec 6, 2024

I'm having some problem reproducing your problem. Could you please fork the https://github.com/cucumber/cucumber-java-skeleton/ and create a minimal reproducer of your problem?

When we have scenarios tagged with @Skip, Cucumber knows to "ignore" each step - even though it goes through the scenario and marks each step individually as "IGNORED." It is also executing all before/after hooks for skipped scenarios.

Cucumber doesn't assign any particular meaning to tags. Without further instruction, tagging a scenario with @Skip will not cause Cucumber to skip that scenario. The only thing that I can think of that comes close to the behavior your describe is using a tagged hook to throw a TestAbortedException. For example by using JUnits Assumptions.

    @Before("@Skip")
    public void before(){
        System.out.println("Before");
        Assumptions.assumeTrue(false);
    }

Is this what you are doing?

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

No branches or pull requests

2 participants