-
Notifications
You must be signed in to change notification settings - Fork 1
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
Allow spec iterations to be skipped #1008
Comments
With #1085 being merged, you can now skip single iterations using |
From my perspective, the important is actually this:
The way you suggest to skip iterations seems fine, but extensions need to be able to "detect" when an iteration was skipped... I couldn't find that addition in the changes you've linked, do you know if that has been added already? |
I don't think so, no. if (exception instanceof AssumptionViolatedException) {
// Spock has no concept of "violated assumption", so we don't notify Spock listeners
// do notify JUnit listeners unless it's a data-driven iteration that's reported as one feature
} else {
masterListener.error(error);
} and from Spock 2.0 if (exception instanceof TestAbortedException || exception instanceof TestSkippedException) {
// Spock has no concept of "aborted tests", so we don't notify Spock listeners
} else {
masterListener.error(transformedError);
} My PR just changed that you do not need to manually throw that exception, but can use the annotations just like for features or specs. |
That code snippet you posted above is exactly the reason why spock-reports cannot know when an iteration is skipped. It relies on a JUnit-specific method to do that, currently. But now that it's possible to skip iterations via Spock itself, I would say Spock should notify its listeners when that happens. In other words, this assertion is no longer correct, right?
As it does now when an iteration is "aborted" due to the use of the |
That comment needs to be rephrased: if (exception instanceof TestAbortedException || exception instanceof TestSkippedException) {
// Spock has no concept of "aborted tests", so we don't notify Spock listeners
} It would have to say |
Hello, renatoathaydes and Vampire, I read your two proposed solution and I have two questions. It is possible to create static method like TestContext.IgnoreTest("Ignored message") which invoke void iterationSkipped? If you implement one of 2 ideas ignoring tests will only be possible from the level of the test itself, but what about some helper classes, where we can check conditions configuration etc for tests? Maybe I miss understanding but I think this ignore feature for iteration should be exists for every place in the code. The second question is whether it would be possible to check several conditions before ignoring the test e.g. Using annotations to ignore tests is ok, but it seems to me that being able to ignore the test elsewhere than in the test gives you more flexibility.
|
The annotation and also the |
Ok, Assume works perfectly, rtretyak has good solution for that with interceptor to catch this exception. Interceptors are awesome. |
I like to ask two questions about this issue:
|
'@stepwise' can now be applied to feature methods. The effects are: 1. the feature be switched to ExecutionMode.SAME_THREAD, similarly to how whole specs are switched to the same execution mode when using the annotation on class level. 2. After the first error or failure occurs in any iteration, all subsequent iterations are going to be skipped. Fixes #1008.
PR #1442 uses another approach: Simply permit |
'@stepwise' can now be applied to feature methods. The effects are: 1. the feature be switched to ExecutionMode.SAME_THREAD, similarly to how whole specs are switched to the same execution mode when using the annotation on class level. 2. After the first error or failure occurs in any iteration, all subsequent iterations are going to be skipped. Fixes #1008.
`@Stepwise` can now be applied to feature methods. The effects are: 1. the feature be switched to `ExecutionMode.SAME_THREAD`, similarly to how whole specs are switched to the same execution mode when using the annotation on class level. 2. After the first error or failure occurs in any iteration, all subsequent iterations are going to be skipped. Fixes #1008
@renatoathaydes, @leonard84: I just stumbled upon this issue again and not am not so sure anymore if my change actually solves this issue. There was no feedback by Renato, so maybe I did not think about this enough when writing in the commit message that this issue is closed by my PR.
This issue, reading it again, seems to be a slightly different use case, namely the ability to skip any iteration based on a condition. For example, of 5 iterations the condition could skip the 2nd and 4th for some reason, but execute all others. This requirement is not solved by Should the issue be re-opened? |
Answering my own question:
No, because this was implemented in another way in #1360, see also #1454 (comment). R.I.P., issue 1008. 😉 |
Feature request
Spock does not currently support natively skipping a single iteration of an examples-based feature. The workaround mentioned in the documentation involves using JUnit's
AssumptionViolatedException
to handle such cases.Spock already correctly reports such iterations as "skipped" to the JUnit
Notifier
, but not to Spock's ownIRunListener
(which, incidentally, causes a bug in spock-reports as it cannot know that a particular iteration of a feature was skipped).It would be ideal to be able to use a Spock, backend-test-framework-independent way of doing this. Specifically, Spock's
IRunListener
should have a method,void iterationSkipped( IterationInfo iteration )
, analogous to the existingvoid specSkipped( SpecInfo spec )
.Proposed solution 1
I would suggest adding a method to
Specification
likevoid skipIf(boolean)
and/orassumeThat(boolean)
, that causes the current feature/iteration to be skipped when necessary.Proposed solution 2
It might be more Spock-like to use a
precondition
block instead:Example
Here's a minimal specification demonstrating how feature iterations can be skipped today, but only when using JUnit APIs.
With the first proposed solution, it would look like this:
With the second proposal:
Thank you for providing the community with a best-in-class testing framework, and hope that this small addition can help make Spock become even better.
The text was updated successfully, but these errors were encountered: