vendredi 1 janvier 2016

Share data tables between Spock test methods

When test methods within a Spock spec use the same data, is there a shortcut way to not have to repeat the same where block in each method?

For example, see the way the where block is repeated in each test method below:

ReindeerSpec extends Specification {

    @Shared
    def reindeers = [makeReindeerOneWay('donner'), makeReindeerSomeOtherWay('blitzen')]

    def 'some test'(Reindeer reindeer) {

        expect:
        // some thing about this reindeer

        where:
        reindeer << reindeers()

    }

    def 'some other test'(Reindeer reindeer) {

        expect:
        // some other thing about this reindeer

        where:
        reindeer << reindeers()

    }

}

Aucun commentaire:

Enregistrer un commentaire