forked from ringcentral/spock
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
`@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
- Loading branch information
Showing
8 changed files
with
322 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
spock-specs/src/test/groovy/org/spockframework/docs/extension/StepwiseDocSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.spockframework.docs.extension | ||
|
||
import org.spockframework.EmbeddedSpecification | ||
import org.spockframework.runtime.extension.builtin.PreconditionContext | ||
import spock.lang.IgnoreIf | ||
|
||
class StepwiseDocSpec extends EmbeddedSpecification { | ||
def "Annotation on spec"() { | ||
runner.throwFailure = false | ||
|
||
when: | ||
def result = runner.runWithImports(/* tag::example-a[] */""" | ||
@Stepwise | ||
class RunInOrderSpec extends Specification { | ||
def "I run first"() { expect: true } | ||
def "I run second"() { expect: false } | ||
def "I will be skipped"() { expect: true } | ||
} | ||
""") // end::example-a[] | ||
|
||
then: | ||
result.testsSucceededCount == 1 | ||
result.testsStartedCount == 2 | ||
result.testsFailedCount == 1 | ||
result.testsSkippedCount == 1 | ||
} | ||
|
||
def "Annotation on feature"() { | ||
runner.throwFailure = false | ||
|
||
when: | ||
def result = runner.runWithImports(/* tag::example-b[] */""" | ||
class SkipAfterFailingIterationSpec extends Specification { | ||
@Stepwise | ||
def "iteration #count"() { | ||
expect: | ||
count != 3 | ||
where: | ||
count << (1..5) | ||
} | ||
} | ||
""") // end::example-b[] | ||
|
||
then: | ||
result.testsStartedCount == 3 + 1 | ||
result.testsSucceededCount == 2 + 1 | ||
result.testsFailedCount == 1 | ||
result.testsSkippedCount == 2 | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
spock-specs/src/test/groovy/org/spockframework/smoke/extension/StepwiseFeatures.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright 2010 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.spockframework.smoke.extension | ||
|
||
import org.spockframework.EmbeddedSpecification | ||
import org.spockframework.runtime.InvalidSpecException | ||
|
||
class StepwiseFeatures extends EmbeddedSpecification { | ||
def "basic usage"() { | ||
runner.throwFailure = false | ||
|
||
when: | ||
def result = runner.runWithImports(""" | ||
class Foo extends Specification { | ||
@Stepwise | ||
def step1() { | ||
expect: count != 3 | ||
where: count << (1..5) | ||
} | ||
} | ||
""") | ||
def expectedSkipMessagesCount = result.testEvents() | ||
.filter({ event -> | ||
event.payload.present && | ||
event.payload.get() == "skipping subsequent iterations after failure" | ||
}) | ||
.count() | ||
|
||
then: | ||
result.testsStartedCount == 3 + 1 | ||
result.testsSucceededCount == 2 + 1 | ||
result.testsFailedCount == 1 | ||
result.testsSkippedCount == 2 | ||
expectedSkipMessagesCount == 2 | ||
} | ||
|
||
def "basic usage rolled-up"() { | ||
runner.throwFailure = false | ||
runner.addClassImport(RollupIterationCounter) | ||
RollupIterationCounter.count.set(0) | ||
|
||
when: | ||
def result = runner.runWithImports(""" | ||
class Foo extends Specification { | ||
@Stepwise | ||
@Rollup | ||
def step1() { | ||
// Keep track of the number of started iterations for later verification in the outer feature method | ||
RollupIterationCounter.count.set(RollupIterationCounter.count.get() + 1) | ||
expect: count != 3 | ||
where: count << (1..5) | ||
} | ||
} | ||
""") | ||
|
||
then: | ||
RollupIterationCounter.count.get() == 3 | ||
result.testsStartedCount == 1 | ||
result.testsSucceededCount == 0 | ||
result.testsFailedCount == 1 | ||
result.testsSkippedCount == 0 | ||
} | ||
|
||
/** | ||
* Has the sole purpose of reporting back the number of started iterations from the rolled-up, stepwise feature method | ||
* used in the embedded spec under test in feature "basic usage rolled-up". | ||
*/ | ||
private static class RollupIterationCounter { | ||
static ThreadLocal<Integer> count = new ThreadLocal<>() | ||
} | ||
|
||
def "annotated feature must be data-driven"() { | ||
when: | ||
def result = runner.runWithImports(""" | ||
class Foo extends Specification { | ||
@Stepwise | ||
def step1() { expect: true } | ||
} | ||
""") | ||
|
||
then: | ||
thrown(InvalidSpecException) | ||
} | ||
|
||
def "feature annotation sets executionMode to SAME_THREAD"() { | ||
when: | ||
def result = runner.runWithImports(""" | ||
import org.spockframework.runtime.model.parallel.ExecutionMode | ||
class Foo extends Specification { | ||
@Stepwise | ||
def step1() { | ||
expect: specificationContext.currentFeature.executionMode.get() == ExecutionMode.SAME_THREAD | ||
where: count << (1..2) | ||
} | ||
} | ||
""") | ||
|
||
then: | ||
result.testsStartedCount == 2 + 1 | ||
result.testsSucceededCount == 2 + 1 | ||
result.testsFailedCount == 0 | ||
result.testsSkippedCount == 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.