Better support for writing functional specs (Idea for a contribution)

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

Hi Constantijn,

That looks pretty neat! Sure, please submit!

Thanks,

Issue opened at

https://github.com/gatling/gatling/issues/2638

Basic code is there, would like some feedback before i make the actual pull request and start writing docs :wink:

This is a great idea. Would love to see it grow beyond REST calls. A lot of applications we test, we usually do UI/data verification using selenium but Gatling’s DSL is more fun to work with.

The implementation i have now should work fine for any sort of HTTP call.

I use jsonPath checks above, but the code above should work out of the box with HTML pages and css or regex checks.

You might be interested in James Pickering’s clickscript.

These are important first steps to functional and load-test tool integration. Why use both Webdriver and Gatling, when we could use just Gatling?

That’s pretty much what was said over here when I started on this :wink:

Working example up at
https://github.com/constantijn/gatling-funtest-example

if people are curious.

Note: For now it requires making 2 snapshot builds of dependent projects to get it to work.