GithubHelp home page GithubHelp logo

ordered-spock's Introduction

Purpose of library

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.

Usage

Building ordered-spock

  1. Build jar and upload to a local maven repository ./gradlew clean build publishToMavenLocal

Usage ordered-spock in project

  1. Add built jar to build.gradle
repositories {
    mavenLocal()
}


testImplementation 'com.github.pgagala:ordered-spock:1.0-SNAPSHOT'
  1. Define a test engine in build.gradle
test {
     useJUnitPlatform() {
        includeEngines 'ordered-spock'
    }
}
  1. Run tests. Every run OrderingAlgorithm affects execution order of specifictions.

Implementing own OrderingAlgorithm

  1. 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());
    }
}
  1. Add a file named META-INF/services/com.github.pgagala.algorithm.OrderingAlgorithm to test resources (default is src/test/resources). Create folders META-INF and services if they don't exist.

  2. 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

ordered-spock's People

Contributors

pgagala avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.