2014-01-10 10 views
2

存在這對於測試我的源代碼:符號值不會的someMethod

import org.openqa.selenium.firefox.FirefoxDriver 
import org.scalatest.FlatSpec 
import org.scalatest.Matchers 

import play.api.test.FakeApplication 
import play.api.test.WithApplication 

class FunctionalSpec extends FlatSpec with Matchers { 
    def withDriver(f: FirefoxDriver => Unit) = { 
    val driver = new FirefoxDriver 
    try { 
     new WithApplication(
     new FakeApplication(additionalConfiguration = Map("application.secret" -> "secret"))) { 
     f(driver) 
     } 
    } finally { 
     driver.quit 
    } 
    } 
} 

它不顯示在Eclipse中任何編譯錯誤。但是當我執行test命令時,它顯示a very long error message。這是錯誤的第一行:

symbol value f$1 does not exist in test.FunctionalSpec$$anon$1$delayedInit$body.apply

我試圖通過修改代碼周圍有點發揮如下所示:

def withDriver(f: FirefoxDriver => Unit) = { 
    val driver = new FirefoxDriver 
    try { 
     val g = f 
     val driver2 = driver 
     new WithApplication(
     new FakeApplication(additionalConfiguration = Map("application.secret" -> "secret"))) { 
     val h = g 
     val driver3 = driver2 
     h(driver3) 
     } 
    } finally { 
     driver.quit 
    } 
    } 

沒有當我執行test命令引發的錯誤。任何想法發生了什麼?爲了保持標識符的可識別性,代碼塊的深度有多大?

編輯: 使用我上面修改的代碼導致runtime-error。我添加代碼如下:

"The admin" should "be able to login and logout correctly" in withDriver { implicit driver => 
    // Don't do anything yet. 
} 

這一個被顯示在運行時間錯誤消息之一行:

Cause: java.lang.NoSuchFieldError: g$1

的解決方法,任何建議?

補充說明: 以上所有代碼編譯都很好。 Eclipse或scalac都不抱怨。以上所有錯誤只有在我執行Play命令shell中的test命令時纔會發生。

+0

你能提供整個堆棧跟蹤?我懷疑測試框架有bug。 –

+0

Hi Rado。謝謝回覆。實際上,我已經在上面提到的鏈接中提供了整個堆棧跟蹤,而不是將它們放在這裏,因爲它們僅僅是很長的。讓我再次把鏈接放在這裏: - [修改之前](http://pastebin.com/FkJJU7UR)。 - [修改後](http://pastebin.com/a4VSgSuP)。 –

+0

可能與https://github.com/scalatest/scalatest/issues/620有關 – cvogt

回答

相關問題