【发布时间】:2011-03-18 12:03:20
【问题描述】:
我编写了以下 Grails 控制器
class CategoryController {
def create = {
def newCategory = new CategoryCommand()
bindData(newCategory, params)
[newCategory: newCategory]
}
}
class CategoryCommand {
String name
String seoName
}
我编写了这个单元测试来测试数据绑定:
class CategoryControllerTests extends ControllerUnitTestCase {
void testCreate() {
// A new ControllerCommand should be returned if invoked with no params
assertNotNull controller.create()
// If called with params, they should be bound
mockParams.name = 'snooker'
mockParams.seoName = 'snooker-loopy'
def model = controller.create()
CategoryCommand newCategory = model.newCategory
assertEquals 'snooker', newCategory.name
assertEquals 'snooker-loopy', newCategory.seoName
}
}
但是当controller.create() 被调用时我得到了这个异常:
方法没有签名:com.example.CategoryController.bindData() 适用于参数类型:(com.example.CategoryCommand, org.codehaus.groovy.grails.web.taglib.GroovyPageAttributes) 值:[com.example .CategoryCommand@7860e7d2, [:]]
我尝试将其作为集成测试运行,但结果相同。
【问题讨论】:
标签: unit-testing grails groovy