gpt4 book ai didi

testing - Grails 不能使用 Spock 框架?

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

我目前正在从事一个项目,该项目一开始并没有适当的 TDD,现在我已采取以下步骤开始使用 Spock 对该项目进行单元和集成测试:

  1. 将以下内容添加到 buildconfig:

    测试“:spock:0.7”

  2. 然后在 "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)

最佳答案

您使用的是 Grails 2.1.0,而 Groovy 2.0 是在 Grails 2.2.0 及更高版本中引入的。希望您不需要显式依赖 org.spockframework:spock-grails-support:0.7-groovy-2.0。仅按以下方式使用:

plugins{
test ":spock:0.7"
}

如果您仍然发现问题,则通过创建一个全新的裸机 grails 应用程序来隔离问题,并按照插件文档中的说明安装插件。尝试查看是否存在任何类路径冲突。如果问题仍然存在,则清除 ivy-cache 和/或 .m2 并重试。

关于testing - Grails 不能使用 Spock 框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17423303/

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