Skip to content

AssumptionViolatedException not causing test to be skipped #1082

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

Closed
murphp15 opened this issue Nov 25, 2016 · 3 comments
Closed

AssumptionViolatedException not causing test to be skipped #1082

murphp15 opened this issue Nov 25, 2016 · 3 comments

Comments

@murphp15
Copy link

murphp15 commented Nov 25, 2016

Summary

We are migrating from an in house BDD framework to cucumber.
In our in house framework tests are skipped if the system is not in a certain state which can only be determined at runtime. We want to be able to support this in cucumber.
For example if test 1 is about to be run it will check that server x and y are active, if not it will skip this test.

Description

I have found a way to mimic this behaviour in cucumber except there seems to be a bug preventing us from doing it.
To mimic it I use tags(annotations) and the before command.
In the before command I check the state of the system, if the system is not how the test wants it then it will throw and org.junit.AssumptionViolatedException. This should cause the step to be skipped.
However we see that this causes the test to fail. We are running our tests in strict mode.

Possible Solution

I have fixed it in a local clone of your repo.
I made the following 2 changes to the file cucumber.runtime.Runtime./
In the runHookIfTagsMatch I added the section
if(isBefore){ status = isPending(t) ? "skipped" : Result.FAILED; }else{ status = isPending(t) ? "pending" : Result.FAILED; }

And in the runStep I changed the line
status = isPending(t) ? "pending" : Result.FAILED;
to
status = isPending(t) ? "skipped" : Result.FAILED;

And in the file JunitReporter.
I changed the method

private void handleHook(Result result) { if(result.getStatus().equalsIgnoreCase("skipped")){ executionUnitNotifier.addFailedAssumption((AssumptionViolatedException) result.getError()); ignoredStep = true; }else if (result.getStatus().equals(Result.FAILED) || (strict && isPending(result.getError()))) { executionUnitNotifier.addFailure(result.getError()); } else if (isPending(result.getError())) { ignoredStep = true; } }

I my no means see this as a full solution and it is untested on other use cases but I would be happy to work with you guys to implement a full solution for this issue.

Looking forward to hearing from you regards, Paul

@mpkorstanje
Copy link
Contributor

We'll be implementing this in version 2.0.0 once #1142 is merged.

@mpkorstanje
Copy link
Contributor

Note that this won't cause tests to be marked as SKIPPED in Cucumber. They'll be defined as PENDING but when non-strict is enabled but these count as skipped in JUnit terms.

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants