Maven surefire-plugin不运行集成测试(按照惯例命名为“IT”后缀),但sbt同时运行:unit和integration。那么,如何防止这种行为呢?是否有一种通用的方法来区分ScalaTest的集成和单元测试(默认情况下不运行FeatureSpec测试)
答案 0 :(得分:19)
如何做到这一点已完全记录在http://www.scala-sbt.org/release/docs/Detailed-Topics/Testing#additional-test-configurations-with-shared-sources上的sbt手册中:
//Build.scala
import sbt._
import Keys._
object B extends Build {
lazy val root =
Project("root", file("."))
.configs( FunTest )
.settings( inConfig(FunTest)(Defaults.testTasks) : _*)
.settings(
libraryDependencies += specs,
testOptions in Test := Seq(Tests.Filter(itFilter)),
testOptions in FunTest := Seq(Tests.Filter(unitFilter))
)
def itFilter(name: String): Boolean = name endsWith "ITest"
def unitFilter(name: String): Boolean = (name endsWith "Test") && !itFilter(name)
lazy val FunTest = config("fun") extend(Test)
lazy val specs = "org.scala-tools.testing" %% "specs" % "1.6.8" % "test"
}
致电sbt test
进行单元测试,sbt fun:test
进行整合测试,sbt test fun:test
进行整合测试。
答案 1 :(得分:2)
使用最新sbt的最简单方法是应用IntegrationTest
配置和所述here所述的相应设置,然后将测试放在项目的src/it/scala
目录中。