2013-02-06 62 views
0

當我嘗試使用下面的代碼來測試拋出的異常:錯誤測試拋出的異常測試

@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的測試應用程序 - 單元

編譯spec'com.genospace.services.EncryptionServiceSpec'期間出現意外錯誤。也許你使用了無效的Spock語法?無論如何,請在http://issues.spockframework.org提交錯誤報告。

java.lang.ClassCastException:org.codehaus.groovy.ast.expr.ArgumentListExpression不能org.codehaus.groovy.ast.expr.DeclarationExpression被轉換爲org.codehaus.groovy.ast.expr.VariableExpression 。 getVariableExpression(DeclarationExpression.java:103) 在org.spockframework.compiler.SpecRewriter.moveVariableDeclarations(SpecRewriter.java:538)

+0

嘗試運行'grails clean'並重新運行測試 –

+0

我試過了,但它似乎沒有幫助 – nialloc

+0

您是否缺少任何導入? –

回答

1

嘗試沒有利用Groovy的多任務功能(def (privateKey,publicCert) = ...)。如果這解決了問題(我想它會),請在http://issues.spockframework.org提交問題。

+0

非常感謝,https://code.google.com/p/spock/issues/detail?id=297 – nialloc