【发布时间】:2013-01-21 20:54:38
【问题描述】:
当我尝试使用以下代码测试抛出的异常时:
@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 语法?无论如何,请在http://issues.spockframework.org 提交错误报告。
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)
【问题讨论】:
-
尝试运行
grails clean并重新运行测试 -
我试过了,但似乎没有帮助
-
您是否缺少任何导入?
-
您使用的是哪个 Grails 版本,以及哪个 Spock 版本?
标签: unit-testing grails spock