如何在单词测试之类的单词规范中进行所有测试之前运行方法?

时间:2017-02-10 22:33:21

标签: scala unit-testing scalatest

如何在scala中运行带有word规范的before方法? 我有这个代码,但是在我的测试之前没有执行before方法:

class SomeClassTest extends TestKit(ActorSystem("test", ConfigFactory.empty())) with WordSpecLike with MockitoSugar with BeforeAndAfter {

override protected def before(fun: => Any): Unit = {
  //some code ...
}

"A SomeClass" must {
  "blah blah blah" in {
    //some code...
  }
 }
}

1 个答案:

答案 0 :(得分:0)

您实际上不必在before中覆盖SomeClassTest,而是通过带有测试设置代码的函数来调用它:

class SomeClassTest extends TestKit(ActorSystem("test", ConfigFactory.empty())) with WordSpecLike with MockitoSugar with BeforeAndAfter {

  before {
    //some code ...
  }

  "A SomeClass" must {
    "blah blah blah" in {
      //some code...
    }
  }

}