[Groovy]Test with Spock

Spock is a testing and specification framework for Java and Groovy applications. What makes it stand out from the crowd is its beautiful and highly expressive specification language.

Link: http://code.google.com/p/spock/ 

sample Maven pom.xml: http://code.google.com/p/spock/wiki/HelloSpockPom 

可以使用when/then 或是 given/expect的组合

import spock.lang.Specification

class Test extends Specification {
    def util = new PackageUtil()
    def result

    def "scenario 1"() {
        when:
            // operations, actions
            result = util.zip("zip package", {
                println it
            })

        then:
        // assertions
        result == true
    }

    def "scenario 2"() {


        given:
        // operations, actions
        result = util.unzip("unzip package", {
            println it
        })

        expect:
        // assertions
        result == true
    }

}
原文地址:https://www.cnblogs.com/buhaiqing/p/2798202.html