dk14
dk14

Reputation: 22374

How to prevent sbt from running integration tests?

Maven surefire-plugin doesn't run integration tests (they named with "IT" suffix by convention), but sbt runs both: unit and integration. So, how to prevent this behaviour? Is there a common way to distinguish integration and unit tests for ScalaTest (don't run FeatureSpec-tests by default)

Upvotes: 13

Views: 4857

Answers (2)

Schleichardt
Schleichardt

Reputation: 7542

How to do that is exactly documented on the sbt manual on http://www.scala-sbt.org/release/docs/Detailed-Topics/Testing#additional-test-configurations-with-shared-sources :

//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"
}

Call sbt test for unit tests and sbt fun:test for integration test and sbt test fun:test for both.

Upvotes: 20

Ilya Klyuchnikov
Ilya Klyuchnikov

Reputation: 3219

The simplest way with the latest sbt is just to apply IntegrationTest config and corresponding settings as described here, - and you put your tests in src/it/scala directory in your project.

Upvotes: 2

Related Questions