Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play! framework: customize which tests are run

I have a Play! 2 for Scala application, and I am using Specs2 for tests. I can run all tests with the test command, or a particular specification with test-only MyParticularSpec.

What I would like to do is mark some particular specifications, or even single methods inside a specification, in order to do things like:

  • running all tests that are not integration (that is, that do not access external resources)
  • running all tests that do not access external resources in write mode (but still running the reading tests)
  • running all tests but a given one

and so on.

I guess something like that should be doable, perhaps by adding some annotations, but I am not sure how to go for it.

Does there exist a mechanism to selectively run some tests and not other ones?

EDIT I have answered myself when using test-only. Still the command line option does not work for the test task. Following the sbt guide I have tried to create an additional sbt configuration, like

object ApplicationBuild extends Build {
  // more settings
  lazy val UnitTest = config("unit") extend(Test)
  lazy val specs = "org.scala-tools.testing" %% "specs" % "1.6.9" % "unit"

  val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA)
    .configs(UnitTest)
    .settings(inConfig(UnitTest)(Defaults.testTasks) : _*)
    .settings(
      testOptions in UnitTest += Tests.Argument("exclude integration"),
      libraryDependencies += specs
    )
}

This works when I pass arguments without options, for instance when I put Test.Argument("plan"). But I was not able to find how to pass a more complex argument. I have tried

Tests.Argument("exclude integration")
Tests.Argument("exclude=integration")
Tests.Argument("-exclude integration")
Tests.Argument("-exclude=integration")
Tests.Argument("exclude", "integration")
Tests.Argument("exclude \"integration\"")

and probably more. Still not any clue what is the correct syntax.

Does anyone know how to pass arguments with options to specs2 from sbt?

like image 611
Andrea Avatar asked Oct 25 '12 08:10

Andrea


2 Answers

First, following the specs2 guide one must add tags to the specifications, like this

class MySpec extends Specification with Tags {
  "My spec" should {
    "exclude this test" in {
      true
    } tag ("foo")

    "include this one" in {
      true
    }
  }
}

The command line arguments to include are documented here

Then one can selectively include or exclude test with

test-only MySpec -- exclude foo
test-only MySpec -- include foo
like image 189
Andrea Avatar answered Oct 17 '22 21:10

Andrea


You can also use without any change to your build

test-only * -- exclude integration

Tested in Play 2.1-RC3

like image 29
Jonas Anso Avatar answered Oct 17 '22 22:10

Jonas Anso