红联Linux门户
Linux帮助

Java测试框架 Spock

发布时间:2012-09-19 10:22:38来源:红联作者:empast
Spock 是适合 Java 和 Groovy 应用程序的一个测试框架。示例代码:[code]import groovy.sql.Sql

import spock.lang.*

class DatabaseDriven extends Specification {
@Shared sql = Sql.newInstance("jdbc:h2:mem:", "org.h2.Driver")

// normally an external database would be used,
// and the test data wouldn't have to be inserted here
def setupSpec() {
sql.execute("create table maxdata (id int primary key, a int, b int, c int)")
sql.execute("insert into maxdata values (1, 3, 7, 7), (2, 5, 4, 5), (3, 9, 9, 9)")
}

def "maximum of two numbers"() {
expect:
Math.max(a, b) == c

where:
[a, b, c] << sql.rows("select a, b, c from maxdata")
}
}[/code]主页:http://code.google.com/p/spock/

下载:http://code.google.com/p/spock/downloads/list

来自:开源中国社区
文章评论

共有 0 条评论