Makes possible to run Spock's specifications in a custom order.
Order is defined by OrderingAlgorithm
.
Default algorithm included in a library (RandomOrderingAlgorithm
) provides random order.
- Build jar and upload to a local maven repository
./gradlew clean build publishToMavenLocal
- Add built jar to
build.gradle
repositories {
mavenLocal()
}
testImplementation 'com.github.pgagala:ordered-spock:1.0-SNAPSHOT'
- Define a test engine in
build.gradle
test {
useJUnitPlatform() {
includeEngines 'ordered-spock'
}
}
- Run tests. Every run
OrderingAlgorithm
affects execution order of specifictions.
- Implementation.
Example below will shuffle specifications in alphabetical order.
Create that class in test scope (default
src/test/groovy
).
package com.app
import com.github.pgagala.algorithm.OrderingAlgorithm
import org.junit.platform.engine.TestDescriptor
import java.util.stream.Collectors
class AlphabeticalOrderAlgorithm implements OrderingAlgorithm {
@Override
<T extends TestDescriptor> List<T> shuffle(List<T> list) {
return list.stream()
.sorted((t1, t2) -> {
t1.getDisplayName() <=> t2.getDisplayName()
})
.collect(Collectors.toUnmodifiableList());
}
}
-
Add a file named
META-INF/services/com.github.pgagala.algorithm.OrderingAlgorithm
to test resources (default issrc/test/resources
). Create foldersMETA-INF
andservices
if they don't exist. -
Add content to file
META-INF/services/com.github.pgagala.algorithm.OrderingAlgorithm
. Content should be full package path to that file. For above example that will be:com.app.AlphabeticalOrderAlgorithm