Hi Gatling Devs,
On my project we’re building a REST API and when it comes to testing we use ScalaTest for most of the unit tests, however at the end of the day we also want to know our API works properly and we decided to use Gatling to write some functional specs against our API.
It works quite well for this purpose but i had to deal with a couple of gotchas (by default failed tests don’t fail the build, SBT plugin had a bug that i already submitted a fix for etc.)
In the end after abstracting away all the boilerplate into the GatlingFunSpec class my tests ended up looking something like this:
class StuffHandlerTest extends GatlingFunSpec {
override val baseURL = "http://localhost:7654/api"
override val httpConf = super.httpConf.header("MyHeader", "MyValue")
spec {
http("GetAll")
.get("/stuff")
.check(stuff exists)
}
spec {
http("GetStuffFromCountryToCountry")
.get("/stuff/NL/NL")
.check(stuff.count is 1)
.check(fromCountry is "NL")
.check(toCountry is "NL")
}
}
object StuffHandlerTest {
def stuff = jsonPath("$.stuff")
def fromCountry = jsonPath("$.stuff[0].fromCountryCode")
def toCountry = jsonPath("$.stuff[0].toCountryCode")
}
Would you guys be interested in a pull request for my GatlingFunSpec implementation? I realize it's nothing new per se, but it would make it quite a bit easier for people to get started writing functional tests using Gatling.
It would require some cleaning up from it's current implementation but I'd be happy to do it (write tests, a manual page,blog post, etc.) and submit a pull request if this seems interesting to you.
Constantijn Visinescu