gpt4 book ai didi

Grails 集成测试无法识别 Controller 保存方法

转载 作者:行者123 更新时间:2023-11-28 20:23:24 24 4
gpt4 key购买 nike

我最近将一个项目从2.2升级到2.4.4,通过替换升级了集成测试

IntegrationTest extends GroovyTestCase 

@TestMixin(IntegrationTestMixin) 

我的 Controller 有保存方法,例如:

class IssueController {

def save() {
...
if (!issueService.save(issue)) {
render(view: "create", model: [issueInstance: issue])
return
}
}

和集成测试(在测试/集成中):

@Before 
void setUp() {
ic = new IssueController()
}

@Test
void testValidSave() {

ic.params.issueNo = "test"

ic.save()
assert ic.flash.successAlert == "Saved issue test"
assert ic.response.redirectUrl == '/issue/list'
}

但是我的集成测试在调用 ic.save() 时不调用 Controller 保存方法(因此失败)。如果我将 save() 方法重命名为 saveIt(),并调用 ic.saveIt(),一切正常

但我不想重命名我所有的 Controller 方法名称。

最佳答案

不需要删除allowedMethods 也不需要改成GET just do in test case

ic.request.method = "POST" 如果允许的方法是 post。

关于Grails 集成测试无法识别 Controller 保存方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28268859/

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