我想测试路线ScalatestRouteTest
如下:
trait MyRoutes extends Directives {
self: Api with ExecutionContextProvider =>
val myRoutes: Route =
pathPrefix("api") {
path("") {
(get & entity(as[MyState])) {
request => {
complete(doSomething(request.operation))
}
}
}
}
}
}
class RoutesSpec extends WordSpecLike with Api with ScalatestRouteTest
with Matchers with MyRoutes with MockitoSugar {
"The Routes" should {
"return status code success" in {
Get() ~> myRoutes ~> check {
status shouldEqual StatusCodes.Success
}
}
}
}
运行测试时出现运行时错误:
无法运行测试 MyRoutesSpec:org.jboss.netty.channel.ChannelException:无法绑定到:/127.0.0.1:2552
我不想绑定到本地主机。如何实现?