我想写单位为我的Grails服务方法之一,单元测试就像是Grails-斯波克:打开设置方法,常用的方法
@Shared instance1, instance2, instance3
class testClass extends Specification {
def setup() {
// initaiting some value here
instance1 = new Initate(one:"one")
instance2 = new Initate(one:"one")
instance3 = new Initate(one:"one")
}
def "testmethodcall"() {
//testsetup()
when:
def result = someMethod(value1) // Here is the error
then:
result==value2
where:
value | value1 | value2
instance1 | instance2 | instance3
}
}
出于某种原因,我们打算提出这里面的代码设置方法的另一种方法,并打算调用它是必需的,这样
@Shared instance1, instance2, instance3
class testClass {
def testsetup() {
// initialize the code what we initialize in setup
// initaiting some value here
instance1 = new Initate(one:"one")
instance2 = new Initate(one:"one")
instance3 = new Initate(one:"one")
}
def "testmethodcall"() {
testsetup()
when:
def result = someMethod(value1) // Here is the error
then:
result==value2
where:
value | value1 | value2
instance1 | instance2 | instance3
}
}
截至目前它是好的,方法调用工作正常,甚至变量进行了初始化,但是当我尝试使用数据列值是返回空值,但是当我更改为setup()
方法我得到真正的价值。有人可以解释我,我怎么能能够改变setUp
方法normal method
我在这里遇到spock的奇怪行为 – 2014-09-24 14:08:08