Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

AssumptionViolatedException when using junit assume #359

Closed
kimsaabyepedersen opened this Issue · 7 comments

2 participants

@kimsaabyepedersen

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

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

@kimsaabyepedersen

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

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

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

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

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

@kimsaabyepedersen

My very first contribution: #363

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.