gpt4 book ai didi

grails - groovy.lang.MissingPropertyException:否这样的属性:为类创建:

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

我正在下面的 Controller 上进行集成测试,这是一个通用项目,用于在Web probject上为FAQ创建类别。并且以下测试返回“groovy.lang.MissingPropertyException:无此类属性:为类创建:”

Controller 代码段:

static allowedMethods = [
index: 'GET', show: 'GET', create: 'GET', edit: 'GET',
save: 'POST', update: 'PUT', delete:'DELETE'
]

...more stuff...

@Transactional
def save(FaqCategory faqCategoryInstance) {
if (faqCategoryInstance == null) {
flash.errorMessage = message(code: 'default.not.found.message', args: [message(code: 'faqCategory.label', default: 'FAQ Category'), params.id])
redirect action: 'index', method: 'GET'
return
}
if (faqCategoryInstance.hasErrors()) {
respond faqCategoryInstance.errors, view:'create'
return
}
if(!faqCategoryInstance.save(flush:true)){
respond faqCategoryInstance.errors, view:'create'
return
}
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.created.message', args: [message(code: 'faqCategory.label', default: 'FAQ Category'), faqCategoryInstance.id])
redirect faqCategoryInstance
}
'*' { respond faqCategoryInstance, [status: CREATED] }
}
}

测试代码段:
@Test
void "test save with null params"(){
def cont = new FaqCategoryController()
cont.request.method = 'GET'
cont.params.id = ''
cont.save()
assertEquals 'FAQ Category not found with id', cont.flash.errorMessage
assertEquals "/faqCategory/index", cont.response.redirectUrl

具有讽刺意味的是,我在非常相似的 Controller 中具有(几乎)完全相同的测试,并且该特定测试根本不会引发任何错误,并且每个文件中的import语句都相同。我知道错误消息,但是我不知道它来自哪里或如何解决。

这也是我上面提到的两个测试文件共有的导入语句:
import static org.junit.Assert.*
import ....DbunitGroovyTestCase // can't show path because of organizational security
import junit.framework.JUnit4TestAdapter
import grails.test.mixin.TestFor
import junit.framework.TestCase

import org.junit.*
import spock.lang.*

-r

最佳答案

您应该使用以下导入语句:import static org.springframework.http.HttpStatus或仅使用简单的错误代码:respond faqCategoryInstance, [status: 201]

关于grails - groovy.lang.MissingPropertyException:否这样的属性:为类创建:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24915651/

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