我目前正在从事一个没有 TDD 的项目,现在我已采取以下步骤开始在该项目上使用 Spock 进行单元和集成测试:
在buildconfig中添加了以下内容:
测试“:spock:0.7”
然后在“test/unit/MYCLASSNAME”创建了一个名为MyfunctionControllerSpec的规范,如下所示:
import grails.test.mixin.* import spock.lang.Specification class MyfunctionControllerSpec extends Specification { void "list() should return no results with no records in DB"() { given: def model = controller.list() expect: model.taskInstanceList.size() == 0 model.taskInstanceTotal == 0 } }
但是,规范导入行出现以下错误:
Groovy:unable to resolve class spock.lang.Specification
我不明白我做错了什么,我是否导入或安装了 Spock 错误?
提前致谢
编辑*
我尝试了下面的建议,然后解决方案无法运行,它仍然无法识别规范类,即使当我开始输入“inport spo”并按 cntrl+space 时也没有出现,就好像它甚至无法识别插件一样:
Loading Grails 2.1.0
| Configuring classpath
| Downloading: spock-grails-support-0.7-groovy-2.0.pom.sha1
| Downloading: spock-core-0.7-groovy-2.0.pom.sha1
| Downloading: spock-grails-support-0.7-groovy-2.0.jar.sha1
| Downloading: spock-core-0.7-groovy-2.0.jar.sha1.
| Environment set to development....
| Error Error loading event script from file [/media/system/workspace/sms_bskyb_New_V2(Dynam Messages)/plugins/tool-ui/scripts/_Events.groovy] startup failed:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/system/.grails/ivy-cache/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.reflect.InvocationTargetException
1 error
(Use --stacktrace to see the full trace)
| Error Error loading event script from file [/home/system/.grails/2.1.0/projects/sms_bskyb/plugins/database-migration-1.1/scripts/_Events.groovy] startup failed:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/system/.grails/ivy-cache/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.reflect.InvocationTargetException
1 error
(Use --stacktrace to see the full trace)
| Error Error loading event script from file [/home/system/.grails/2.1.0/projects/sms_bskyb/plugins/tomcat-2.1.0/scripts/_Events.groovy] startup failed:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/system/.grails/ivy-cache/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.reflect.InvocationTargetException
1 error
(Use --stacktrace to see the full trace)
| Error Error loading event script from file [/home/system/.grails/2.1.0/projects/sms_bskyb/plugins/spock-0.7/scripts/_Events.groovy] startup failed:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/system/.grails/ivy-cache/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.reflect.InvocationTargetException
1 error
(Use --stacktrace to see the full trace)
| Error Error loading event script from file [/home/system/.grails/2.1.0/projects/sms_bskyb/plugins/webxml-1.4.1/scripts/_Events.groovy] startup failed:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/system/.grails/ivy-cache/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.reflect.InvocationTargetException
1 error
(Use --stacktrace to see the full trace)
| Environment set to development.....
| Packaging Grails application.
| Error Fatal error during compilation org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/system/.grails/ivy-cache/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.reflect.InvocationTargetException
1 error
(Use --stacktrace to see the full trace)