spock-genesis

Mostly lazy data generators for property based testing using the Spock test framework

License

License

Categories

Categories

Spock Application Testing & Monitoring
GroupId

GroupId

com.nagternal
ArtifactId

ArtifactId

spock-genesis
Last Version

Last Version

0.6.0
Release Date

Release Date

Type

Type

jar
Description

Description

spock-genesis
Mostly lazy data generators for property based testing using the Spock test framework
Project URL

Project URL

https://bijnagte.github.io/spock-genesis
Source Code Management

Source Code Management

https://github.com/Bijnagte/spock-genesis.git

Download spock-genesis

How to add to project

<!-- https://jarcasting.com/artifacts/com.nagternal/spock-genesis/ -->
<dependency>
    <groupId>com.nagternal</groupId>
    <artifactId>spock-genesis</artifactId>
    <version>0.6.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.nagternal/spock-genesis/
implementation 'com.nagternal:spock-genesis:0.6.0'
// https://jarcasting.com/artifacts/com.nagternal/spock-genesis/
implementation ("com.nagternal:spock-genesis:0.6.0")
'com.nagternal:spock-genesis:jar:0.6.0'
<dependency org="com.nagternal" name="spock-genesis" rev="0.6.0">
  <artifact name="spock-genesis" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.nagternal', module='spock-genesis', version='0.6.0')
)
libraryDependencies += "com.nagternal" % "spock-genesis" % "0.6.0"
[com.nagternal/spock-genesis "0.6.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.codehaus.groovy : groovy-all jar 2.4.7
org.spockframework : spock-core jar 1.0-groovy-2.4
com.github.mifmif : generex jar 1.0.1

test (1)

Group / Artifact Type Version
cglib : cglib-nodep jar 3.2.4

Project Modules

There are no modules declared in this project.

Spock Genesis

Mostly lazy data generators for property based testing using the Spock test framework

Providing test data, especially when attempting to test for a wide range of inputs is tedious if not impossible to do by hand. Generating inputs allows for more thorough testing without a dramatic increase in effort. In Spock [data driven tests] (http://spock-framework.readthedocs.org/en/latest/data_driven_testing.html#data-pipes) can have data provided by any Iterator. Spock Genesis provides a variety of classes that extend from Generator which meet that interface. Where possible the generators are lazy and infinite.

build status codecov JCenter Maven Central

Usage

From gradle:

repositories {
    jcenter()
}

dependencies {
    testCompile 'com.nagternal:spock-genesis:0.6.0'
}

The primary way of constructing generators is spock.genesis.Gen which provides static factory methods for data generators.

@Unroll
def 'test reverse #string'() {
    when:
        def reversed = string.reverse()

    then:
        reversed.size() == string.size()
        if (string) {
            string.eachWithIndex { letter, i ->
                letter == reversed[-(i + 1)]
            }
        }
        reversed.reverse() == string

    where:
        string << Gen.these('', 'foo').then(Gen.string).take(10000)
}

Given a Person class create a generator that can supply instances:

    Gen.type(Person,
        id: Gen.integer(200..10000),
        name: Gen.string(~/[A-Z][a-z]+( [A-Z][a-z]+)?/),
        birthDate: Gen.date(Date.parse('MM/dd/yyyy','01/01/1940'), new Date()),
        title: Gen.these('', null).then(Gen.any('Dr.', 'Mr.', 'Ms.', 'Mrs.')),
        gender: Gen.character('MFTU'))

Documentation

Check Spock-Genesis documentation is here or see SamplesSpec for more examples

Change log

0.2.0

  • Update dependencies

0.3.0

  • Add support for using regular expressions for String generation. Thanks to Generex
  • Using Groovy constructor selection for single arg Pojo construction

0.4.0

  • improve toGenerator extension methods
  • better error handling for POJO construction
  • isFinite method to determine if generator will terminate

0.5.0

  • switch to Iterable from Iterator
  • improve performance of long generation using min and/or max
  • improved documentation (thanks to @mariogarcia)
  • @Iterations annotation
  • updated dependencies
  • ability to set the seed of random generators

0.6.0

  • permute to generate combinations from composite generators

Building Spock Genesis

The only prerequisite is that you have JDK 7 or higher installed.

After cloning the project, type ./gradlew clean build (Windows: gradlew clean build). All build dependencies, including Gradle itself, will be downloaded automatically (unless already present).

Resources

Versions

Version
0.6.0
0.5.0