【发布时间】:2013-01-27 22:04:35
【问题描述】:
mongodb-1.1.0GA 的文档在单元测试部分似乎已经过时:http://springsource.github.com/grails-data-mapping/mongo/manual/ref/Testing/DatastoreUnitTestMixin.html
以下代码
@TestFor(Employee)
class EmployeeTests extends GroovyTestCase {
void setUp() {
}
void tearDown() {
}
void testSomething() {
mockDomain(Employee)
def s = new Employee(firstName: "first name", lastName: "last Name", occupation: "whatever")
s['testField'] = "testValue"
s.save()
assert s.id != null
s = Employee.get(s.id)
assert s != null
assert s.firstName == "first name"
assert s['testField'] == "testValue"
}
}
失败并出现此错误:
No such property: testField for class: Employee
Employee 类非常简单:
class Employee {
String firstName
String lastName
String occupation
static constraints = {
firstName blank: false, nullable: false
lastName blank: false, nullable: false
occupation blank: false, nullable: false
}
}
那么,是否可以对动态属性进行单元测试?如果是,如何?
【问题讨论】:
标签: unit-testing mongodb grails grails-orm