0

We have REST API written in Java . I want to write some unit tests in Scala to the REST API. I am looking for a lean, easy to use framework to use (an example or link to example can be helpful) .

igx
  • 4,101
  • 11
  • 43
  • 88

2 Answers2

0

The Play! framework WS API works really well in my opinion. You can use it as a standalone module as described here.

Some examples from the linked page:

GET request with authentication:

WS.url(url).withAuth(user, password, WSAuthScheme.BASIC).get()

GET request with query parameters:

WS.url(url).withQueryString("paramKey" -> "paramValue").get()

POST request with JSON body:

import play.api.libs.json._
val data = Json.obj(
  "key1" -> "value1",
  "key2" -> "value2"
)
val futureResponse: Future[WSResponse] = WS.url(url).post(data)

That last one also requires you to import the Play! JSON library. If you don't need to manipulate them, you can always just pass your JSON payload serialised as a string - without having to use the JSON library.

Zoltán
  • 21,321
  • 14
  • 93
  • 134
0

You should try SPECS 2: Link to SPECS2 Web

I recommend you to use it with ScalaMock to have the best tools to test your API.