同一个 Play 项目中的 Gatling 负载测试和 ScalaTest 单元测试
Gatling load tests and ScalaTest unit tests in same Play project
到目前为止,我们一直在使用 ScalaTestPlusPlay 进行项目中的测试,但是
最近决定尝试一些 Gatling 负载测试。我们要 3
可以分别运行的测试组:
- 普通单元测试(通过 "test")
- 集成测试(通过 "it:test")
- 负载测试(通过 "gatling-it:test")
不幸的是,我只能让组 1&2 或组 2&3 成为
随时可用。如果未启用 Gatling 插件,则该单元
可以执行测试和集成测试。
但是如果我添加:
enablePlugins(GatlingPlugin)
到 build.sbt,我获得了 运行 Gatling 负载测试的能力,但是在
原始单元测试的费用。 "test" 任务仍然可以执行,
但没有测试 类 是 found/ran.
built.sbt
libraryDependencies ++= Seq(
"org.postgresql" % "postgresql" % "9.3-1100-jdbc4",
"org.flywaydb" % "flyway-sbt" % "3.0",
"org.dbunit" % "dbunit" % "2.5.1" % "test,it",
"org.scalatest" %% "scalatest" % "2.2.4" % "test,it",
"org.scalatestplus" %% "play" % "1.4.0-M3",
"org.jdom" % "jdom" % "1.1.2" notTransitive(),
"org.pac4j" % "play-pac4j-scala_2.11" % "1.5.0",
"org.pac4j" % "pac4j-http" % "1.7.1",
"jp.t2v" %% "play2-auth" % "0.13.2",
"jp.t2v" %% "play2-auth-test" % "0.13.2" % "test,it",
"javax.jms" % "javax.jms-api" % "2.0.1",
"org.apache.activemq" % "activemq-all" % "5.11.1",
"io.gatling.highcharts" % "gatling-charts-highcharts" % "2.1.7" % "test",
"io.gatling" % "gatling-test-framework" % "2.1.7" % "test",
"com.typesafe.play" %% "anorm" % "2.4.0",
jdbc,
ws,
cache
)
Defaults.itSettings
lazy val ItTest = config("it") extend(Test)
lazy val GatlingTest = config("gatling-it") extend(ItTest)
enablePlugins(GatlingPlugin)
def loadTestFilter(name: String): Boolean = (name endsWith "LoadTest")
def itTestFilter(name: String): Boolean = (name endsWith "IntegrationTest")
def unitTestFilter(name: String): Boolean = ((name endsWith "Suite"))
sourceDirectory in IntegrationTest := baseDirectory.value / "test/it"
testOptions in Gatling := Seq(Tests.Filter(loadTestFilter))
testOptions in ItTest := Seq(Tests.Filter(itTestFilter))
testOptions in Test := Seq(Tests.Filter(unitTestFilter))
lazy val root = (project in file("."))
.enablePlugins(PlayScala)
.configs(ItTest) settings( inConfig(ItTest)(Defaults.testTasks) : _*)
// Failed attempt at isolating gatling tests
lazy val gatling = project.in(file("."))
.enablePlugins(GatlingPlugin)
))
project/plugins.sbt
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.2") // It works from Play 2.3.2
addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.0")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.6.0")
// Generate ctags for project. Yes, I am probably the only one who cares
addSbtPlugin("net.ceedubs" %% "sbt-ctags" % "0.1.0")
resolvers += "sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases/"
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.1")
// Gatling Stress Testing
addSbtPlugin("io.gatling" % "gatling-sbt" % "2.1.7")
那么我怎样才能在不丢失所有单元的情况下访问新的 Gatling 测试呢?
测试?
这里是 Gatling 的 SBT 插件的维护者。
很遗憾,您不是第一个遇到此问题的人,我正在努力解决这个问题。
作为临时解决方法,您可以通过使用 test:test
而不是 test
来恢复单元测试和 运行。
它应该为 Gatling 2.1.8 修复 ;)
我通常将 gatling 移动到这样的子项目中,在 build.sbt:
lazy val gtl = Project("gtl", File("gtl")).settings(....).enablePlugins(GatlingPlugin)
aggregate in Test := false
然后通过sbt
执行
gtl/it:test or gtl/test
到目前为止,我们一直在使用 ScalaTestPlusPlay 进行项目中的测试,但是 最近决定尝试一些 Gatling 负载测试。我们要 3 可以分别运行的测试组:
- 普通单元测试(通过 "test")
- 集成测试(通过 "it:test")
- 负载测试(通过 "gatling-it:test")
不幸的是,我只能让组 1&2 或组 2&3 成为 随时可用。如果未启用 Gatling 插件,则该单元 可以执行测试和集成测试。
但是如果我添加:
enablePlugins(GatlingPlugin)
到 build.sbt,我获得了 运行 Gatling 负载测试的能力,但是在 原始单元测试的费用。 "test" 任务仍然可以执行, 但没有测试 类 是 found/ran.
built.sbt
libraryDependencies ++= Seq(
"org.postgresql" % "postgresql" % "9.3-1100-jdbc4",
"org.flywaydb" % "flyway-sbt" % "3.0",
"org.dbunit" % "dbunit" % "2.5.1" % "test,it",
"org.scalatest" %% "scalatest" % "2.2.4" % "test,it",
"org.scalatestplus" %% "play" % "1.4.0-M3",
"org.jdom" % "jdom" % "1.1.2" notTransitive(),
"org.pac4j" % "play-pac4j-scala_2.11" % "1.5.0",
"org.pac4j" % "pac4j-http" % "1.7.1",
"jp.t2v" %% "play2-auth" % "0.13.2",
"jp.t2v" %% "play2-auth-test" % "0.13.2" % "test,it",
"javax.jms" % "javax.jms-api" % "2.0.1",
"org.apache.activemq" % "activemq-all" % "5.11.1",
"io.gatling.highcharts" % "gatling-charts-highcharts" % "2.1.7" % "test",
"io.gatling" % "gatling-test-framework" % "2.1.7" % "test",
"com.typesafe.play" %% "anorm" % "2.4.0",
jdbc,
ws,
cache
)
Defaults.itSettings
lazy val ItTest = config("it") extend(Test)
lazy val GatlingTest = config("gatling-it") extend(ItTest)
enablePlugins(GatlingPlugin)
def loadTestFilter(name: String): Boolean = (name endsWith "LoadTest")
def itTestFilter(name: String): Boolean = (name endsWith "IntegrationTest")
def unitTestFilter(name: String): Boolean = ((name endsWith "Suite"))
sourceDirectory in IntegrationTest := baseDirectory.value / "test/it"
testOptions in Gatling := Seq(Tests.Filter(loadTestFilter))
testOptions in ItTest := Seq(Tests.Filter(itTestFilter))
testOptions in Test := Seq(Tests.Filter(unitTestFilter))
lazy val root = (project in file("."))
.enablePlugins(PlayScala)
.configs(ItTest) settings( inConfig(ItTest)(Defaults.testTasks) : _*)
// Failed attempt at isolating gatling tests
lazy val gatling = project.in(file("."))
.enablePlugins(GatlingPlugin)
))
project/plugins.sbt
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.2") // It works from Play 2.3.2
addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.0")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.6.0")
// Generate ctags for project. Yes, I am probably the only one who cares
addSbtPlugin("net.ceedubs" %% "sbt-ctags" % "0.1.0")
resolvers += "sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases/"
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.1")
// Gatling Stress Testing
addSbtPlugin("io.gatling" % "gatling-sbt" % "2.1.7")
那么我怎样才能在不丢失所有单元的情况下访问新的 Gatling 测试呢? 测试?
这里是 Gatling 的 SBT 插件的维护者。
很遗憾,您不是第一个遇到此问题的人,我正在努力解决这个问题。
作为临时解决方法,您可以通过使用 test:test
而不是 test
来恢复单元测试和 运行。
它应该为 Gatling 2.1.8 修复 ;)
我通常将 gatling 移动到这样的子项目中,在 build.sbt:
lazy val gtl = Project("gtl", File("gtl")).settings(....).enablePlugins(GatlingPlugin)
aggregate in Test := false
然后通过sbt
执行gtl/it:test or gtl/test