FakeApplication does not really lunch a web process, so you cannot test using http access to localhost.
You have three options:
- Testing the controller directly
- Testing the router
- Testing the whole app.
Testing the controller is done by directly calling your controller and checking the result, as suggested in play documentation, and providing a FakeRequest()
val result = controllers.Application.index("Bob")(FakeRequest())
Testing the router is done by calling routeAndCall with a FakeRequest argument, specifying the relative path:
val Some(result) = routeAndCall(FakeRequest(GET, "/Bob"))
Eventually, if you want to test your whole application, you need to start a TestServer:
"run in a server" in {
running(TestServer(3333)) {
await(WS.url("http://localhost:3333").get).status must equalTo(OK)
}
}
Your question says: "What is the best option?". The answer is: there is nothing such as a best option, there are different way of testing for different purpose. You should pick up the testing strategy which better fits your requirement. In this case, since you want to test the router, I suggest you try approach n.2