简体   繁体   English

Spray,ScalaTest和HTTP服务:找不到参数ta的隐式值:

[英]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 这为我的代码解决了这个问题

Spray.io: Can't compile test spec Spray.io:无法编译测试规范

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 spray-json错误:无法找到参数um的隐含值 - spray-json error: could not find implicit value for parameter um 找不到参数编组器的隐式值:spray.httpx.marshalling.ToResponseMarshaller [Unit] - could not find implicit value for parameter marshaller: spray.httpx.marshalling.ToResponseMarshaller[Unit] spray-json递归json问题-找不到证据参数的隐式值 - spray-json recursive json issue - could not find implicit value for evidence parameter 使用spray.json序列化多态类获取无法找到类型为证据的隐式值 - serializing polymorphic classes using spray.json getting could not find implicit value for evidence parameter of type 找不到参数marshaller的隐含值:spray.httpx.marshalling.ToResponseMarshaller - could not find implicit value for parameter marshaller: spray.httpx.marshalling.ToResponseMarshaller 原因“找不到参数rs的隐式值:spray.routing.RoutingSettings” - Reason for “could not find implicit value for parameter rs: spray.routing.RoutingSettings” 这作为隐式参数-找不到参数的隐式值 - this as implicit parameter - could not find implicit value for parameter 使用Scalatest测试Spray服务时,如何引入隐式值? - When testing Spray services with Scalatest, how to introduce implicit values? spray-json:找不到FromRequestUnmarshallar的隐式值 - spray-json: could not find implicit value for FromRequestUnmarshallar akka-http:找不到参数解组的隐含值 - akka-http : could not find implicit value for parameter unmarshalling
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM