gpt4 book ai didi

grails - 在Controller中使用域类时,在测试完 Controller 后将返回错误

转载 作者:行者123 更新时间:2023-12-02 14:40:09 26 4
gpt4 key购买 nike

我有一个用grails编写的 Controller ,其中我使用了域类的名称来从db检索数据。现在,我要使用grails默认测试对其进行测试。

但是它返回一个错误:

java.lang.IllegalStateException: Either class [cre_service.AppPreferences] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.

最佳答案

听起来您需要模拟域类,例如

import spock.lang.Specification
import grails.test.mixin.Mock

@Mock( [AppPreferences] )
class YourControllerClassSpec extends Specification {
...

关于grails - 在Controller中使用域类时,在测试完 Controller 后将返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41700038/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com