Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 单元测试因GrailsConfigurationException失败-找不到负责的代码行_Unit Testing_Grails_Spock_Grails 3.0 - Fatal编程技术网

Unit testing 单元测试因GrailsConfigurationException失败-找不到负责的代码行

Unit testing 单元测试因GrailsConfigurationException失败-找不到负责的代码行,unit-testing,grails,spock,grails-3.0,Unit Testing,Grails,Spock,Grails 3.0,我正在使用标准spock框架为Grails3.0.3应用程序编写单元测试。一切都是用脚手架搭起来的 grails create-app 我用 grails create-unit-test 手动添加@TestFor注释和测试逻辑。我明白了 mypackage.MyClassSpec > test myMethod method FAILED org.grails.core.exceptions.GrailsConfigurationException 运行后stacktrace

我正在使用标准spock框架为Grails3.0.3应用程序编写单元测试。一切都是用脚手架搭起来的

grails create-app  
我用

grails create-unit-test
手动添加@TestFor注释和测试逻辑。我明白了

mypackage.MyClassSpec > test myMethod method FAILED
org.grails.core.exceptions.GrailsConfigurationException

运行后stacktrace中没有行号

grails test-app --stacktrace
如何找出导致此异常的原因?

该注释用于测试Grails人工制品(是的,源代码中就是这样拼写的)

TestFor注释定义了被测试的类,并将 自动为测试中的类类型创建字段。对于 示例:在上述情况下,将出现“控制器”字段, 但是,如果为服务定义了TestFor,则“服务”字段将 被创造等等


您正在测试的类是一个普通的Groovy类,而不是Grails控制器、服务等!您遇到了一个尴尬的异常。

toTsv(listOfMaps)方法需要做什么工作?配置设置?其他服务?这些都需要在单元测试用例中模拟。如果没有看到toTsv代码,很难有任何具体的帮助想法。您好,谢谢您的评论。这是一个独立的方法,不依赖任何外部服务,它只接受一个地图列表。但是我已经解决了这个问题-我删除了@TestFor注解。。。现在它开始工作了。我仍然想理解它失败的原因,我仍然在学习Grails和Spock,所以这可能是一些基本的错误。