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

AssumptionViolatedException when using junit assume #359

Closed
kimsaabyepedersen opened this issue Jul 16, 2012 · 8 comments
Closed

AssumptionViolatedException when using junit assume #359

kimsaabyepedersen opened this issue Jul 16, 2012 · 8 comments

Comments

@kimsaabyepedersen
Copy link

I have a cucumber test that starts something like this:

@Before
public void assume() throws Exception {
    wd = new SharedDriver();
    wd.get("http://127.0.0.1:4444/TEST/");
   Assume.assumeTrue(wd.getTitle().contains("TestIt"));
}

//After this comes a lot of methods

I want to use the @before (which is the cucumber one and not the unit) to stop my test if the assumption fails. However, the scenario fails (the individual steps are ignored). This is very annoying as my build breaks.

How can I use an Assume and make cucumber ignore the scenario (and report no errors)?

StackTrace:

org.junit.internal.AssumptionViolatedException: got: , expected: is
at org.junit.Assume.assumeThat(Assume.java:70)
at org.junit.Assume.assumeTrue(Assume.java:39)
at Myclass.assume(Myclass.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cucumber.runtime.Utils$1.call(Utils.java:40)
at cucumber.runtime.Timeout.timeout(Timeout.java:12)
at cucumber.runtime.Utils.invoke(Utils.java:36)
at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:59)
at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:182)
at cucumber.runtime.Runtime.runHooks(Runtime.java:174)
at cucumber.runtime.Runtime.runBeforeHooks(Runtime.java:165)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:32)
at cucumber.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:76)
at cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:65)
at cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:20)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at cucumber.junit.FeatureRunner.run(FeatureRunner.java:72)
at cucumber.junit.Cucumber.runChild(Cucumber.java:76)
at cucumber.junit.Cucumber.runChild(Cucumber.java:36)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at cucumber.junit.Cucumber.run(Cucumber.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

@aslakhellesoy
Copy link
Contributor

Please enlighten me about what Assume is supposed to do. I've never used it.

@kimsaabyepedersen
Copy link
Author

Hi Aslak.

From the Assume javadoc (http://junit.sourceforge.net/javadoc/org/junit/Assume.html):

"A set of methods useful for stating assumptions about the conditions in which a test is meaningful. A failed assumption does not mean the code is broken, but that the test provides no useful information. The default JUnit runner treats tests with failing assumptions as ignored. Custom runners may behave differently. "

Specifically on assumeTrue:
"If called with an expression evaluating to false, the test will halt and be ignored."

I use assume to enable / disable different tests depending on the environment that the run in (and I would prefer not to do this using e.g. tags). The benefit of assume is that the tests which "fails" the assumption will be ignored.

@aslakhellesoy
Copy link
Contributor

Cucumber-Core (where the exception will be caught and reported) doesn't depend on junit, so this would require a patch that just looks at the exception class name to determine whether or not to allow the step to pass.

I'd happily accept a pull-request for this.

@kimsaabyepedersen
Copy link
Author

Okay, should the exception class name just be hard coded in the core, or how do you propose that we tell core the class name?

@aslakhellesoy
Copy link
Contributor

Yes, I suggest we have a private static final List<String> PASS_THROUGH_EXCEPTION_CLASS_NAMES that will allow a step to pass if the thrown exception name is one of those.

@kimsaabyepedersen
Copy link
Author

OK, I'll try to fix it during this week and send you a pull-request.

@kimsaabyepedersen
Copy link
Author

My very first contribution: #363

@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