【发布时间】:2015-07-10 00:38:09
【问题描述】:
我正在尝试为具有 .class 参数的方法编写单元测试。
例如:
ExampleService {
def myExample(clazz){
//do stuff and return some object
}
}
/* How the above function gets used */
AnotherExampleService extends exampleService {
def blah() {
def obj = myExample(AnotherClass.class)
}
}
/* Now I need to test the above blah() function */
AnotherExampleServiceSpec extends Specification {
def "test blah"() {
//The following doesn't seem to work
ExampleService.metaClass.myExample = { def arg1 -> obj }
}
}
我对 Groovy/Grails 还很陌生,因此我们将不胜感激。我基本上想知道为什么我的单元测试似乎不起作用,以及如何测试这样一个接受类实例参数的函数。
感谢您的帮助!
【问题讨论】:
标签: unit-testing grails groovy