Play! framework: customize which tests are run

后端 未结 5 968
温柔的废话
温柔的废话 2021-02-13 15:11

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-on

相关标签:
5条回答
  • 2021-02-13 15:20

    You can also use without any change to your build

    test-only * -- exclude integration
    

    Tested in Play 2.1-RC3

    0 讨论(0)
  • 2021-02-13 15:26

    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
    
    0 讨论(0)
  • 2021-02-13 15:40

    I'm using Play2.2, and there are 2 ways to do this depending on whether or not you are in the play console.

    1. From the console type: test-only full.namespace.to.TestSpec
    2. From the terminal type: test-only "full.namespace.to.TestSpec"
    0 讨论(0)
  • 2021-02-13 15:40

    I came across this question while trying to figure out how to do something similar for ScalaTest with Play. SBT has detailed documentation on how to configure additional test configurations but these could use a bit of tweaking for Play.

    Apart from the subtly different Project configuration I found that I wanted to crib a bunch of the test settings from PlaySettings. The following is running and generating an Intellij project with integration test sources in the "/it" directory. I may still be missing reporting and lifecycle hooks,

    object BuildSettings {
      def testSettings = {
        // required for ScalaTest. See http://stackoverflow.com/questions/10362388/using-scalatest-in-a-playframework-project
        testOptions in Test := Nil
      }
    
      def itSettings = {
        // variously cribbed from https://github.com/playframework/Play20/blob/master/framework/src/sbt-plugin/src/main/scala/PlaySettings.scala
        sourceDirectory in IntegrationTest <<= baseDirectory / "it"
        scalaSource in Test <<= baseDirectory / "it"
        libraryDependencies += "play" %% "play-test" % play.core.PlayVersion.current % "it"
      }
    }
    
    object ApplicationBuild extends Build {
      val main = play.Project(
        appName,
        appVersion,
        Dependencies.dependencies)
        .configs( IntegrationTest )
        .settings(Dependencies.resolutionRepos)
        .settings(BuildSettings.testSettings)
        .settings(Defaults.itSettings : _*)
        .settings(BuildSettings.itSettings)
    }
    
    0 讨论(0)
  • 2021-02-13 15:44

    If you want to pass several arguments you can add several strings to one Test.Argument

    testOptions in Test += Tests.Argument("include", "unit")
    

    There are examples of this in the specs2 User Guide here and in the Play documentation there.

    0 讨论(0)
提交回复
热议问题