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

Throwing AssumptionViolatedException not reporting the Test Case at all in serenity reports. #2998

Closed
despellhtb opened this issue Dec 22, 2022 · 2 comments

Comments

@despellhtb
Copy link

When throwing an AssumptionViolatedException in steps (somewhere in your test case anyway) Serenity will handle this as SKIPPED and will record the test case as IGNORED.

But this is not the case when throwing an AssumptionViolatedException in Cucumber event listeners plugin.
Below you can find my custom cucumber listener:

package base.runner.plugins;

import io.cucumber.plugin.EventListener;
import io.cucumber.plugin.event.EventPublisher;
import io.cucumber.plugin.event.TestCaseStarted;
import org.junit.AssumptionViolatedException;

public class BeforeTestCase implements EventListener {
    @Override
    public void setEventPublisher(final EventPublisher publisher) {
        publisher.registerHandlerFor(TestCaseStarted.class, this::onTestCaseStarted);
    }

    private void onTestCaseStarted(final TestCaseStarted event) {
       throw new AssumptionViolatedException("skip");
    }
}

And of course the runner:

package base.runner;

import io.cucumber.junit.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.runner.RunWith;

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
        plugin = {"pretty","base.runner.plugins.BeforeTestCase"},
        features = "src/test/resources/features",
        glue = "steps",
        tags = ""
)
public class Cucumber {}

I don't know if that is even an issue, or it has been already reported in the past.
Seems pretty strange.

@wakaleo
Copy link
Member

wakaleo commented Dec 22, 2022

I can see in the code this isn't catered for - it will just be silently skipped, as . Handling it looks non-trivial, as the Serenity listeners are bypassed in that case (the test is simply not run, which is the normal behaviour for an AssumptionViolatedException). Could be a future enhancement.

@despellhtb
Copy link
Author

There are many ways to achieve that. As an example you can use cucumber hooks (@before) and throw the assumption there. I just want to have everything in place.

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