为 grails 运行 test-app -coverage 命令时出现错误,即使所有测试用例都通过了
Posted
技术标签:
【中文标题】为 grails 运行 test-app -coverage 命令时出现错误,即使所有测试用例都通过了【英文标题】:Getting an Error while running test-app -coverage command for grails even all test case passed 【发布时间】:2012-12-13 17:33:05 【问题描述】:我使用的是 Grails 2.1.1,而对于代码覆盖插件,我使用的是 code-coverage1.2.5
我注意到我的测试用例通过 test-app 命令成功通过,但没有通过命令“test-app -coverage --stacktrace”生成 cobertura 报告
下面是我遇到的错误
Flushing results done
Cobertura: Loaded information on 320 classes.
Cobertura: Saved information on 320 classes.
| Error Exception occurred trigger event [TestPhasesEnd]: Could not create a new instance of class [com.sigmainfo.cooptimum.connectplus.priorapproval.PriorApprovalController]! (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
org.codehaus.groovy.grails.exceptions.NewInstanceCreationException: Could not create a new instance of class [com.sigmainfo.cooptimum.connectplus.priorapproval.PriorApprovalController]!
at _Events$_replaceClosureNames_closure5.doCall(_Events.groovy:115)
at _Events.replaceClosureNames(_Events.groovy:113)
at _Events$replaceClosureNames.callCurrent(Unknown Source)
at _Events.replaceClosureNamesInReports(_Events.groovy:105)
at _Events$_run_closure3.doCall(_Events.groovy:59)
at _GrailsEvents_groovy$_run_closure5.doCall(_GrailsEvents_groovy:53)
at _GrailsEvents_groovy$_run_closure5.call(_GrailsEvents_groovy)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:223)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy)
at java_util_concurrent_Callable$call.call(Unknown Source)
at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at TestApp$_run_closure1.doCall(TestApp.groovy:82)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy)
at java_util_concurrent_Callable$call.call(Unknown Source)
at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy)
at java_util_concurrent_Callable$call.call(Unknown Source)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at java_util_concurrent_Callable$call.call(Unknown Source)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:591)
at gant.Gant.executeTargets(Gant.groovy:590)
Caused by: groovy.lang.MissingMethodException: No signature of method: com.sigmainfo.cooptimum.connectplus.DealerBaseInfo.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure)
at com.sigmainfo.cooptimum.connectplus.DealerBaseInfo.findAll(DealerBaseInfo.groovy)
at com.sigmainfo.cooptimum.connectplus.DealerBaseInfo$findAll.call(Unknown Source)
at com.sigmainfo.cooptimum.connectplus.priorapproval.PriorApprovalController.<init>(PriorApprovalController.groovy:32)
... 42 more
| Error Exception occurred trigger event [TestPhasesEnd]: Could not create a new instance of class [com.sigmainfo.cooptimum.connectplus.priorapproval.PriorApprovalController]!
Flushing results...
Flushing results done
Cobertura: Loaded information on 320 classes.
Cobertura: Saved information on 320 classes.
下面是控制器的sn-p代码
class PriorApprovalController extends FileUploaderController
Subject currentUser = SecurityUtils.subject
def baseRecordList = DealerBaseInfo.findAll("from DealerBaseInfo as dealers",[cache: false])
def dataSource
def mailSenderService
def exportService
def priorApprovalInfo
def currentuser
def dealerBaseInfo1
我在线路上遇到错误
def baseRecordList = DealerBaseInfo.findAll("from DealerBaseInfo as dealers",[cache: false])
【问题讨论】:
您应该考虑提供更多信息,而不仅仅是线程标题和一些堆栈跟踪... 请在您的问题中添加更多详细信息;导致错误的代码的 sn-p,您怀疑是什么导致了错误以及您尝试了什么 您至少应该提供您调用的 Grails 版本和完整的命令行。 def baseRecordList = DealerBaseInfo.findAll("从 DealerBaseInfo 作为经销商",[cache: false]) def dataSource def mailSenderService def exportService def priorApprovalInfo def currentuser def dealBaseInfo1 def dummyUserList = [ '11111111', '22222222 ', '33333333', '44444444' ] def dummyEmails = [ 'asad.ansari.mail@gmail.com' ] def index() 【参考方案1】:发现你的所有调用不应该在类级别调用你的域没有注入你可以尝试在域中使用静态方法并调用该方法
【讨论】:
以上是关于为 grails 运行 test-app -coverage 命令时出现错误,即使所有测试用例都通过了的主要内容,如果未能解决你的问题,请参考以下文章
在 Grails 应用程序中为长时间运行的作业构建队列的最佳方法是啥?