[英]Spray, ScalaTest and HTTP services: could not find implicit value for parameter ta:
I am, again, struggling with spray and cannot set up a test correctly. 我再次在喷雾中挣扎,无法正确设置测试。 I looked at the similar question spray-testkit: could not find implicit value for parameter ta: and the official spray template and cannot figure out what I am missing and/or doing wrong.
我看了类似的问题spray-testkit:找不到参数ta的隐式值:以及官方的Spray模板 ,也无法弄清楚我缺少和/或做错了什么。
I have a very simple service: 我有一个非常简单的服务:
trait SimpleService extends HttpService{
val fooRoute = path("foo") {
get {
complete("bar")
}
}
}
And I have a very simple test: 我有一个非常简单的测试:
class SimpleServiceTest extends FlatSpec with Matchers with SimpleService with ScalatestRouteTest {
override implicit def actorRefFactory: ActorRefFactory = system
"The service" should "return OK status when getting /foo" in {
Get("/foo") ~> fooRoute ~> check {
status should be(OK)
}
}
}
when I try to compile this, I get the following error: 当我尝试对此进行编译时,出现以下错误:
Error:(17, 17) could not find implicit value for parameter ta: SimpleServiceTest.this.TildeArrow[spray.routing.RequestContext,Unit]
Get("/foo") ~> fooRoute ~> check {
^
Can anyone help me and tell me what I am missing? 谁能帮助我,告诉我我所缺少的吗? I do not find anything unusual, and I am close to evaluating Play instead of spray.
我没有发现任何异常,并且我即将评估Play而不是喷雾。
You should mixin ScalatestRouteTest
before SimpleService
, like so: 您应该在
SimpleService
之前混合ScalatestRouteTest
,如下所示:
class SimpleServiceTest extends ScalatestRouteTest with FlatSpec with Matchers with SimpleService
Another possible solution is to add the following lines to where your test throws the Implicit not found: 另一种可能的解决方案是将以下行添加到测试抛出未找到的隐式的位置:
implicitly[spray.testkit.RouteTestTimeout]
implicitly[spray.routing.RoutingSettings]
implicitly[spray.util.LoggingContext]
See which line throws, and provide the implicit for that type. 查看哪些行引发,并提供该类型的隐式。
The ScalatestRouteTest already provides an implicit ActorySystem. ScalatestRouteTest已经提供了一个隐式的ActorySystem。 Remove the "implicit" modifier from your actorRefFactory method and the test should get executed.
从actorRefFactory方法中删除“隐式”修饰符,然后将执行测试。
this solve this problem for my code 这为我的代码解决了这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.