我正在嘗試爲Spark作業設置測試框架。我想使用spark-testing-base的SharedSparkContext特性,它依賴於ScalaTest的BeforeAndAfterAll特性來管理安裝和拆卸。關於我當前環境的一些事情正在導致在每個測試用例周圍調用beforeAll和afterAll方法。 (即使我想允許這種多餘的行爲,我不能:我不知道如何正確拆除我的HiveContext對象,所以第二次調用beforeAll時會拋出一個異常,它出現在「ERROR XSDB6 :Derby的另一個實例可能已經啓動了數據庫/ Users/applemacbookpro/git/my-project/metastore_db。「)用sbt和IntelliJ IDEA使用ScalaTest的BeforeAndAfterAll特質的正確方法是什麼?
我正在使用IntelliJ IDEA和SBT管理的構建。
- 的MacOS 10.11.4
- 的IntelliJ IDEA 2016年1月3日
- 不知道SBT版本,應該是最近
- ScalaTest 2.2.6
每火花測試的自述-base和this question,我把
parallelExecution in Test := false
in build.sbt。
這裏是我的例子:
import org.scalatest.{BeforeAndAfterAll, FlatSpec}
class ExampleSpec extends FlatSpec with BeforeAndAfterAll {
override def beforeAll(): Unit = {
println("in beforeAll")
super.beforeAll()
}
override def afterAll() {
println("in afterAll")
super.afterAll()
}
behavior of "example"
it should "succeed" in {
println("test 1")
}
it should "succeed again" in {
println("test2")
}
}
我在編輯器窗口中單擊鼠標右鍵並從上下文菜單中運行觸發它;輸出是:
/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/bin/java...
Testing started at 2:50 PM ...
in beforeAll
test 1
in afterAll
in beforeAll
test2
in afterAll
Process finished with exit code 0
對於Scala-2.10和Scala-2.11,無法使用Windows-7/IntelliJ-2016.2/SBT-0.13.12/ScalaTest-2.2.6進行復制。 – heenenee