installation - org.scalatest : Global setup (like beforeAllSuites? )

标签 installation sbt scalatest

我有一个使用 org.scalatest 进行一些测试的 Scala 应用程序。这些测试需要一些全局设置(和拆卸),以便管理测试数据库。

请不要告诉我我的测试不应该访问数据库,我应该使用 Java-DAO-Stub-WTF-Overkill-Way™ :-)。

我正在使用 SBT 运行测试,它提供了一种在测试前后执行代码的方法:

    testOptions in Test += Tests.Setup( () => println("Setup") )

    testOptions in Test += Tests.Cleanup( () => println("Cleanup") )

不幸的是,我无法访问那里的相关类(class)。不出所料,将它们导入 build.sbt 也不起作用。

有任何想法吗?

最佳答案

您可以使用 BeforeAndAfterAllBeforeAndAfter特点,看你的需求。

之前和之后:

Trait that can be mixed into suites that need methods invoked before and after executing the suite. This trait allows code to be executed before and/or after all the tests and nested suites of a suite are run.



因此,在这种情况下,您将定义一个包含所有其他套件/测试的 MasterSuite,它扩展了此特征。

之前和之后:

Trait that can be mixed into suites that need code executed before and after running each test. This trait facilitates a style of testing in which mutable fixture objects held in instance variables are replaced or reinitialized before each test or suite.

关于installation - org.scalatest : Global setup (like beforeAllSuites? ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8486869/

相关文章:

scala - Play+Scala 套件测试未找到类型 PlaySpecification

scala - Gen.sequence 忽略给定 Traversable 的大小

installation - 使用高级安装程序合并模块

java - MacOS 应用程序的设置

postgresql - 在 SBT 的修订部分中为 Postgres 依赖添加什么

scala - Scalatest 的 Wiremock 集成问题

scala - 如何使用intellij运行多模块sbt的所有scalatest?

google-chrome - Chromium 的自定义安装程序

windows - 基于服务器的应用程序安装程序创建新组是否可以接受?

scala - SBT 本地 Maven 存储库依赖