mtrebi
mtrebi

Reputation: 267

Test API REST SCALA

I am developing an application with Scala, Akka and Spray and I want to test the services of the API.

I do not understand howspray-testkit helps us in testing. I also tried Specs2 and ScalaTest but neither of them are made to test APIs.

I just want a library that allow me to test API paths, adding headers, jsons to body and assert HTTP status and so son. What do you suggest me?

[EDIT]

I also tried Frisby.js and it is more simple. Maybe it is a better choice.

[EDIT -2]

I found Gatling. Does anyone know it??

Thanks!

Upvotes: 3

Views: 5497

Answers (3)

Lubo
Lubo

Reputation: 1827

Mentioned gatling, I need to advocate for it. It is IMHO successor of JMeter and it does miracles in terms of efficiency in performance testing (HTTP, AMQP, ...). You can take down any un-optimized web application with some small nettop easily.

Beware that DSL of gatling does heavily use fluent scripting and also builder pattern a lot. I.e. debugging your suite does require a bit of skill and knowledge of gatling internals.

For regression testing I would rather stick to scalatest, but if you mind, do all your tests in gatling. It can be really readable and it can doublecheck performance of your app if needed.

Upvotes: 1

mtrebi
mtrebi

Reputation: 267

With the help of @jmccure and also another question on SO and this blog I find the way to do it.

For example, this is how my first test looks like:

test("Create User") {
 Post("/users", user) ~> userRoutes ~> check {
  assert(
    status == OK
    && responseAs[User] == user
   ) 
  }
}

Where user is a case class that can be marshalled.

Upvotes: 3

Related Questions