gpt4 book ai didi

unit-testing - 单元测试因GrailsConfigurationException失败-无法找到负责任的代码行

转载 作者:行者123 更新时间:2023-12-02 15:05:41 25 4
gpt4 key购买 nike

我正在使用标准spock框架为Grails 3.0.3应用程序编写单元测试。一切都由脚手架

grails create-app  

我创建了我的单元测试
grails create-unit-test

手动添加了@TestFor批注和测试逻辑。我懂了
mypackage.MyClassSpec > test myMethod method FAILED
org.grails.core.exceptions.GrailsConfigurationException

GIST of My test class (generalized and simplified)

运行后,堆栈跟踪中没有行号
grails test-app --stacktrace

我如何找出导致此异常的原因?

最佳答案

TestFor批注用于测试Grails伪像(是的,这就是它在源代码中的拼写方式)。

The TestFor annotation defines the class under test and will automatically create a field for the type of class under test. For example in the above case a "controller" field will be present, however if TestFor was defined for a service a "service" field would be created and so on.



您正在测试的类是普通的Groovy类,而不是Grails Controller ,服务等。因此,BAM!你有一个尴尬的异常(exception)。

关于unit-testing - 单元测试因GrailsConfigurationException失败-无法找到负责任的代码行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32140989/

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