Discussion:
[Cucumber] How to skip a scenario with Cucumber-JVM at run-time in JAVA
(too old to reply)
Deena P
2018-02-01 14:23:16 UTC
Permalink
Raw Message
I need to skip a scenario from running based on a flag which I obtain from
the application dynamically in run-time, which tells whether the feature to
be tested is enabled. I don't want to throw any exception.

Sample code:

} else {
status = zapi.getTestExecutionStatusInJIRA(scenario.getName());
if (status.equalsIgnoreCase("pass")) {
isScenarioAlreadyPassed = true;
} else {
isScenarioAlreadyPassed = false;
}
}
} else {
logger.info("Currently JIRA_Integration is disabled, enable it to update test scenario execution status in JIRA");
}

if (isScenarioAlreadyPassed) {
logger.info("Scenario: \"" + scenario.getName() + "\" is already passed in the previous test cycle");
throw new SkipException("\"Scenario: \\\"\" + scenario.getName() + \"\\\" is already passed in the previous test cycle\"");
}


Problem with above approach is failed test still shows up as Error in the test summary. I want these scenario/test to be skipped completely or proceed with next scenario/test.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Björn Rasmusson
2018-02-02 17:43:19 UTC
Permalink
Raw Message
Post by Deena P
I need to skip a scenario from running based on a flag which I obtain from
the application dynamically in run-time, which tells whether the feature to
be tested is enabled. I don't want to throw any exception.
} else {
status = zapi.getTestExecutionStatusInJIRA(scenario.getName());
if (status.equalsIgnoreCase("pass")) {
isScenarioAlreadyPassed = true;
} else {
isScenarioAlreadyPassed = false;
}
}
} else {
logger.info("Currently JIRA_Integration is disabled, enable it to update test scenario execution status in JIRA");
}
if (isScenarioAlreadyPassed) {
logger.info("Scenario: \"" + scenario.getName() + "\" is already passed in the previous test cycle");
throw new SkipException("\"Scenario: \\\"\" + scenario.getName() + \"\\\" is already passed in the previous test cycle\"");
}
Problem with above approach is failed test still shows up as Error in the test summary. I want these scenario/test to be skipped completely or proceed with next scenario/test.
Use assumeTrue("<message>", false); (
http://junit.org/junit4/javadoc/4.12/org/junit/Assume.html#assumeTrue(java.lang.String,%20boolean)),
then the scenarios will show up as Skipped in the summary.

Cheers
Björn
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Deena P
2018-02-02 19:08:46 UTC
Permalink
Raw Message
No assumeTrue also showing as error in result summary
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Björn Rasmusson
2018-02-03 10:44:22 UTC
Permalink
Raw Message
Post by Deena P
No assumeTrue also showing as error in result summary
I added a assumeTrue(false); locally to one of the step definitions of the java-calculator
example
<https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-calculator>
and got the following summary:
8 Scenarios (1 skipped, 7 passed)
36 Steps (3 skipped, 33 passed)

You must be using a to old version of Cucumber-JVM. The latest Cucumber-JVM
release is v2.3.1
<http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22cucumber-jvm%22>, AFAIK
you have to use v2.0.0 or later to get this summary.

Cheers
Björn
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Deena P
2018-02-03 14:45:13 UTC
Permalink
Raw Message
Thanks for the response Björn.

After upgrading cucumber-JVM, cucumber scenario execution status is showing
correctly in the terminal. like the one you mentioned.

Skipped step

Skipped step

1 Scenarios (1 skipped)
2 Steps (2 skipped)
0m0.535s

But again the problem, maven build is getting failed due to the
org.junit.AssumptionViolatedException

Tests run: 12, Failures: 1, Errors: 0, Skipped: 0

[INFO]
------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 8.791 s
[INFO] Finished at: 2018-02-03T20:10:08+05:30
Post by Björn Rasmusson
Post by Deena P
No assumeTrue also showing as error in result summary
I added a assumeTrue(false); locally to one of the step definitions of
the java-calculator example
<https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-calculator>
8 Scenarios (1 skipped, 7 passed)
36 Steps (3 skipped, 33 passed)
You must be using a to old version of Cucumber-JVM. The latest
Cucumber-JVM release is v2.3.1
<http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22cucumber-jvm%22>,
AFAIK you have to use v2.0.0 or later to get this summary.
Cheers
Björn
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Björn Rasmusson
2018-02-03 16:23:37 UTC
Permalink
Raw Message
Post by Deena P
Thanks for the response Björn.
After upgrading cucumber-JVM, cucumber scenario execution status is
showing correctly in the terminal. like the one you mentioned.
Skipped step
Skipped step
1 Scenarios (1 skipped)
2 Steps (2 skipped)
0m0.535s
But again the problem, maven build is getting failed due to the
org.junit.AssumptionViolatedException
Tests run: 12, Failures: 1, Errors: 0, Skipped: 0
[INFO]
------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 8.791 s
[INFO] Finished at: 2018-02-03T20:10:08+05:30
I do not get a maven build failure (using a Junit runner class
<https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator/src/test/java/cucumber/examples/java/calculator/RunCukesTest.java>).
maven-surefire does get an assumptionFailed notification, and does
correctly mark the test as skipped:

8 Scenarios (1 skipped, 7 passed)
36 Steps (3 skipped, 33 passed)
0m0.601s

org.junit.AssumptionViolatedException: got: <false>, expected: is <true>
at org.junit.Assume.assumeThat(Assume.java:95)
at org.junit.Assume.assumeTrue(Assume.java:41)
at cucumber.examples.java.calculator.ShoppingStepdefs.
the_following_groceries(ShoppingStepdefs.java:22)
at ✜.the following groceries:(cucumber/examples/java/calculator/shopping
.feature:4)

[WARNING] Tests run: 8, Failures: 0, Errors: 0, Skipped: 1, Time elapsed:
1.521 s - in cucumber.examples.java.calculator.RunCukesTest
[INFO]
[INFO] Results:
[INFO]
[WARNING] Tests run: 8, Failures: 0, Errors: 0, Skipped: 1
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ java-calculator ---
[INFO]
------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Cucumber-JVM ....................................... SUCCESS [ 0.928
s]
[INFO] Cucumber-JVM: Core ................................. SUCCESS [ 24.236
s]
[INFO] Cucumber-JVM: JUnit ................................ SUCCESS [ 3.881
s]
[INFO] Cucumber-JVM: Java ................................. SUCCESS [ 20.609
s]
[INFO] Examples ........................................... SUCCESS [ 0.052
s]
[INFO] Examples: Java Calculator .......................... SUCCESS [ 4.569
s]
[INFO]
------------------------------------------------------------------------
[INFO] BUILD SUCCESS
Post by Deena P
Post by Björn Rasmusson
Post by Deena P
No assumeTrue also showing as error in result summary
I added a assumeTrue(false); locally to one of the step definitions of
the java-calculator example
<https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-calculator>
8 Scenarios (1 skipped, 7 passed)
36 Steps (3 skipped, 33 passed)
You must be using a to old version of Cucumber-JVM. The latest
Cucumber-JVM release is v2.3.1
<http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22cucumber-jvm%22>,
AFAIK you have to use v2.0.0 or later to get this summary.
Cheers
Björn
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Deena P
2018-02-03 16:28:12 UTC
Permalink
Raw Message
ok, I was using testNg runner. Let me try with Junit.

Thank you very much!
Post by Björn Rasmusson
Post by Deena P
Thanks for the response Björn.
After upgrading cucumber-JVM, cucumber scenario execution status is
showing correctly in the terminal. like the one you mentioned.
Skipped step
Skipped step
1 Scenarios (1 skipped)
2 Steps (2 skipped)
0m0.535s
But again the problem, maven build is getting failed due to the
org.junit.AssumptionViolatedException
Tests run: 12, Failures: 1, Errors: 0, Skipped: 0
[INFO]
------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 8.791 s
[INFO] Finished at: 2018-02-03T20:10:08+05:30
I do not get a maven build failure (using a Junit runner class
<https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator/src/test/java/cucumber/examples/java/calculator/RunCukesTest.java>).
maven-surefire does get an assumptionFailed notification, and does
8 Scenarios (1 skipped, 7 passed)
36 Steps (3 skipped, 33 passed)
0m0.601s
org.junit.AssumptionViolatedException: got: <false>, expected: is <true>
at org.junit.Assume.assumeThat(Assume.java:95)
at org.junit.Assume.assumeTrue(Assume.java:41)
at cucumber.examples.java.calculator.ShoppingStepdefs.
the_following_groceries(ShoppingStepdefs.java:22)
at ✜.the following groceries:(cucumber/examples/java/calculator/
shopping.feature:4)
1.521 s - in cucumber.examples.java.calculator.RunCukesTest
[INFO]
[INFO]
[WARNING] Tests run: 8, Failures: 0, Errors: 0, Skipped: 1
[INFO]
[INFO]
[INFO]
------------------------------------------------------------------------
[INFO]
[INFO] Cucumber-JVM ....................................... SUCCESS [
0.928 s]
[INFO] Cucumber-JVM: Core ................................. SUCCESS [
24.236 s]
[INFO] Cucumber-JVM: JUnit ................................ SUCCESS [
3.881 s]
[INFO] Cucumber-JVM: Java ................................. SUCCESS [
20.609 s]
[INFO] Examples ........................................... SUCCESS [
0.052 s]
[INFO] Examples: Java Calculator .......................... SUCCESS [
4.569 s]
[INFO]
------------------------------------------------------------------------
[INFO] BUILD SUCCESS
Post by Deena P
Post by Björn Rasmusson
Post by Deena P
No assumeTrue also showing as error in result summary
I added a assumeTrue(false); locally to one of the step definitions of
the java-calculator example
<https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-calculator>
8 Scenarios (1 skipped, 7 passed)
36 Steps (3 skipped, 33 passed)
You must be using a to old version of Cucumber-JVM. The latest
Cucumber-JVM release is v2.3.1
<http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22cucumber-jvm%22>,
AFAIK you have to use v2.0.0 or later to get this summary.
Cheers
Björn
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...