我一直在用spock和grails进行测试,但是遇到了以下问题。我试图对HQL语句进行如下简单测试:
@Transactional
class UserService {
List<User> getAll() {
List<User> lUser = User.executeQuery('Select u.age from User u')
return lUser
}
}
为此,我使用了以下测试:
@Mock(User)
@TestFor(UserService)
class UserServiceSpec extends Specification {
void "test service"() {
when:
def res = service.getAll()
then:
assert true
}
}
执行它时,出现以下错误。
java.lang.UnsupportedOperationException: String-based queries like [executeQuery] are currently not supported in this implementation of GORM. Use criteria instead.
at org.grails.datastore.gorm.GormStaticApi.unsupported(GormStaticApi.groovy:880)
at org.grails.datastore.gorm.GormStaticApi.executeQuery(GormStaticApi.groovy:800)
at test.UserService.getAll(UserService.groovy:9)
at test.UserServiceSpec.test service(UserServiceSpec.groovy:16)
有人知道如何在不使用条件的情况下解决问题吗?
PD:我正在使用grails 2.3.6和Hibernate 3.6.10.8