0
votes

I have a Play framework with a bunch of tests (which are run with ScalaTest), and I am trying to organize them by:

  • Unit test
  • Integration Test Read
  • Integration Test Write

I have left all of my unit tests untagged, and have created the following tags:

/* TestTags.scala */

object IntegrationReadTest extends Tag("IntegrationReadTest")
object IntegrationWriteTest extends Tag("IntegrationWriteTest")

so that I can tag my integration tests like this:

/* SomeSpecs.scala */

"foo" taggedAs IntegrationReadTest in {
  // External APIs are read from
}

"bar" taggedAs IntegrationWriteTest in {
  // External APIs are written to
}

Most of the time while I am developing and running tests, I do not want to run the integration tests, so I modified my build.sbt to ignore them when I run sbt test:

/* build.sbt */

testOptions in Test += Tests.Argument("-l", "IntegrationReadTest")
testOptions in Test += Tests.Argument("-l", "IntegrationWriteTest")

This all works well, but I cannot figure how to run all of the tests (including the integration tests). I have tried many combinations of sbt test and sbt "test:testOnly" but can not figure out how to un-ignore the integration tests.

1

1 Answers

2
votes

By default, your tests run in the Test context. This means that sbt test is really doing sbt test:test. Since you are setting testOptions in Test, this applies by default.

From that, it follows that you can create a new context All which puts those tests back in.

/* build.sbt */

lazy val All = config("all") extend(Test) describedAs("run all the tests")
configs(All)
inConfig(All)(Defaults.testSettings)

testOptions in All -= Tests.Argument("-l", "IntegrationReadTest")
testOptions in All -= Tests.Argument("-l", "IntegrationWriteTest")

Then you can run sbt all:test to run them all.