Play MockWS is a mock WS client for Play Framework.
If:
- you write an application in Scala with the Play Framework
- the application makes HTTP calls to external web services with the WS client
- you want to test your implementation
then you can use play-mockws
to simulate HTTP requests to external web services in your tests.
// simulation of a GET request to http://dns/url
val ws = MockWS {
case (GET, "http://dns/url") => Action { Ok("http response") }
}
await(ws.url("http://dns/url").get()).body == "http response"
The simulation of the HTTP response for the WS call is simply implemented with a standard Play Action.
An example how to structure an implementation to test it with MockWS can be found here.
Other examples can be found in the tests.
Add MockWS as test dependency in the build.sbt
:
libraryDependencies += "de.leanovate.play-mockws" %% "play-mockws" % "0.9" % "test"
The last version can be found on Maven Central
And use it:
import mockws.MockWS
val ws = MockWS { ... }
MockWS is actually only compatible with Play 2.3.x., with Scala 2.10 or 2.11.