1

私は現在、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)
4

2 に答える 2

1

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再試行してください。

于 2013-07-02T13:53:15.317 に答える