Why are integration tests in a Play/Scala project not executed when using “sbt it:test”?

后端 未结 2 441
被撕碎了的回忆
被撕碎了的回忆 2021-02-02 16:39

I have a Play Framework 2.3 project in which I\'d like to separate unit tests and functional tests as follows:

  1. running sbt test should run unit tests
2条回答
  •  借酒劲吻你
    2021-02-02 17:04

    This is what I ended up doing, which allows me to:

    1. keep my integration tests in play's /test directory
    2. run sbt test for Unit Tests and sbt fun:test for functional/integration tests

    Here is the build.sbt, no need for a project/Build.scala

    libraryDependencies ++= Seq(
      ...
      "com.typesafe.play" %% "play-json" % "2.2.3",
      "org.scalatest" %% "scalatest" % "2.1.5" % "test",
      "org.mockito" % "mockito-all" % "1.9.5" % "test"
    )
    
    lazy val FunTest = config("fun") extend(Test)
    
    def funTestFilter(name: String): Boolean = ((name endsWith "ItTest") || (name endsWith "IntegrationTest"))
    def unitTestFilter(name: String): Boolean = ((name endsWith "Test") && !funTestFilter(name))
    
    lazy val root = project in file(".") configs(FunTest) settings( inConfig(FunTest)(Defaults.testTasks) : _*)
    
    testOptions in FunTest := Seq(Tests.Filter(funTestFilter))
    
    testOptions in Test := Seq(Tests.Filter(unitTestFilter))
    

提交回复
热议问题