Scalatest 中是否有相当于 @Before 或 beforeEach 的东西

Man*_*dha 4 scalatest

测试框架jasmine提供junit了在每次测试运行之前配置测试环境的方法。scalatest和中有类似的东西吗playspec

Mat*_*ski 8

在 scalatest 中,您可以使用特征BeforeAndAfterAllBeforeAndAfterEach添加此类方法,然后您需要覆盖它们:

class BaseTest extends FlatSpec with BeforeAndAfterAll with BeforeAndAfterEach{

  override def beforeAll(): Unit = {
    super.beforeAll()
    //your logic here
  }

  //..

}
Run Code Online (Sandbox Code Playgroud)