Spock Web Console

subscribe to the feed Subscribe
sisg - 04 Spock Basics: Parameterized Tests - List (via #spockwebconsole)
tweet this script Tweet

sisg - 04 Spock Basics: Parameterized Tests - List

Published 3 months ago by Matthias Schulz with tags sisg Spock Basics Paramete
Actions  ➤ Edit In Console Back To Console Show/Hide Line Numbers View Recent Scripts
package parameter

import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll

// This tag lists each parameterized test separately:
@Unroll
class ParameterizedListSpec extends Specification{

    @Shared int[] data = [1, 2, 3, 4, 5]


    def "Test #value * #value"() {
        expect:
        expected == value * value

        where:
        value  << data
        expected << [1, 4, 9, 16, 25]
    }


    def "Test #value + #value"() {
        when:
        int result = value + value

        then:
        result == expected
        result == 2 * value
        result > value

        where: "Test data"
        value  << data
        expected << [2, 4, 6, 8, 10]
    }
}