forked from spockframework/spock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New built-in, global RandomRunOrderExtension
Supports run order randomization for specifications, features or a combination of both. Relates to spockframework#1443.
- Loading branch information
Showing
5 changed files
with
80 additions
and
1 deletion.
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
42 changes: 42 additions & 0 deletions
42
...e/src/main/java/org/spockframework/runtime/extension/builtin/RandomRunOrderExtension.java
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,42 @@ | ||
/* | ||
* Copyright 2023 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 | ||
* https://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.runtime.extension.builtin; | ||
|
||
import org.spockframework.runtime.extension.IGlobalExtension; | ||
import org.spockframework.runtime.model.FeatureInfo; | ||
import org.spockframework.runtime.model.SpecInfo; | ||
import spock.config.RunnerConfiguration; | ||
|
||
import java.util.Random; | ||
|
||
public class RandomRunOrderExtension implements IGlobalExtension { | ||
private static final Random RANDOM = new Random(); | ||
|
||
private final RunnerConfiguration config; | ||
|
||
public RandomRunOrderExtension(RunnerConfiguration config) { | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public void visitSpec(SpecInfo spec) { | ||
if (config.randomizeSpecRunOrder) | ||
spec.setExecutionOrder(RANDOM.nextInt()); | ||
if (config.randomizeFeatureRunOrder) { | ||
for (FeatureInfo featureInfo : spec.getAllFeatures()) | ||
featureInfo.setExecutionOrder(RANDOM.nextInt()); | ||
} | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
...rc/main/resources/META-INF/services/org.spockframework.runtime.extension.IGlobalExtension
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
org.spockframework.runtime.extension.builtin.IncludeExcludeExtension | ||
org.spockframework.runtime.extension.builtin.OptimizeRunOrderExtension | ||
org.spockframework.runtime.extension.builtin.RandomRunOrderExtension | ||
org.spockframework.runtime.extension.builtin.UnrollExtension |