Issue
I have Cucumber .feature file with multiple test cases (using "Examples").
In some situation i want to skip few of the test cases and run only few of them.
Note:
User should be able to select which test case to skip dynamically
For example, he can decide in first run to skip test case number 1, next time to skip number 2.
Examples:
| SERIAL_NO | ID |
| 1 | Create-Customer A |
| 2 | Create-Customer B |
| 3 | Create-Customer C |
I managed to do that using
Assume.assumeTrue(...)
The only issue is - code throws Exception, and i want to keep logs clear.
There is any option to avoid print the exception, and just ignore the test case ? or skip it by another solution ?
Thanks
Solution
Finally I found a simple solution, by using the same method i have mentioned Assert.assume(...), just need to clear the exception stack trace, and re-throw it.
In below code you can see the actual change is just i added the catch block:
try
{
Assume.assumeTrue("Some Condition...");
}
catch (AssumptionViolatedException e)
{
// clearing stack trace, so it will keep logs clear, just print the name of exception
e.setStackTrace(new StackTraceElement[] {});
throw e;
}
Now exception stack trace is not printed to log, so logs kept clean, and i just see this instead:
org.junit.AssumptionViolatedException: got: <false>, expected: is <true>
This is good enough for me.
Answered By - Adir D