We have been using ScalaTestPlusPlay for the tests in our project so far, but recently decided to try out some Gatling load tests. We want 3 groups of tests that can be run separately:
Unfortunately I have only either been able to get groups 1&2 or 2&3 to be available at any given time. If the Gatling plugin is not enabled, the unit tests and integration tests can be executed.
But if I add:
enablePlugins(GatlingPlugin)
to build.sbt, I gain the ability to run the Gatling load tests, but at the expense of the original unit tests. The "test" task can still be executed, but no test classes are 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")
So how can I get access to the new Gatling tests without losing all the unit tests?
maintainer of Gatling's SBT plugin here.
You're unfortunately not the first to bump into this issue, and I'm working on a fix.
As a temporary workaround, you can get your unit tests back and running by using test:test
instead of test
.
It should be fixed for Gatling 2.1.8 ;)
I usually move gatling into a sub-project like this, in build.sbt:
lazy val gtl = Project("gtl", File("gtl")).settings(....).enablePlugins(GatlingPlugin)
aggregate in Test := false
then execute via sbt
gtl/it:test or gtl/test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With