Unit testing 测试Spock单元测试中引发的异常时出错

Unit testing 测试Spock单元测试中引发的异常时出错,unit-testing,grails,spock,Unit Testing,Grails,Spock,当我尝试使用以下代码测试抛出的异常时: @TestFor(EncryptionService) class EncryptionServiceSpec extends Specification { def "test decryption of unecnrypted file"(){ setup: def clearTextFile = new File("test/resources/clearText.txt") clearTextFile.wr

当我尝试使用以下代码测试抛出的异常时:

@TestFor(EncryptionService)
class EncryptionServiceSpec extends Specification {
def "test decryption of unecnrypted file"(){
    setup: 
        def clearTextFile = new File("test/resources/clearText.txt")
        clearTextFile.write("THIS IS CLEAR TEXT")

    when:
        def (privateKey,publicCert) = service.generateKeyPair("123")
        service.decryptFile(new FileInputStream(clearTextFile), privateKey )

    then:
        clearTextFile.delete()
        thrown GeneralSecurityException
}
}
当我运行grails test app-unit时,会出现以下编译异常

编译规范“com.genospace.services.EncryptionServiceSpec”时出现意外错误。可能您使用了无效的Spock语法?无论如何,请在提交错误报告

java.lang.ClassCastException:org.codehaus.groovy.ast.expr.ArgumentListExpression不能强制转换为org.codehaus.groovy.ast.expr.VariableExpression 位于org.codehaus.groovy.ast.expr.DeclarationExpression.getVariableExpression(DeclarationExpression.java:103) 位于org.spockframework.compiler.SpecRewriter.moveVariableDeclarations(SpecRewriter.java:538)


尝试不利用Groovy的多重分配功能(
def(privateKey,publicCert)=……
)。如果这解决了问题(我认为会),请将问题提交到。

尝试运行
grails clean
并重新运行测试。我尝试过,但似乎没有帮助您是否缺少任何导入?您使用的是哪一个确切的grails版本,以及哪一个确切的Spock版本?