Mat*_*ini 10 testing scala akka spray
我有以下服务:
trait PingService extends MyHttpService {
val pingRoutes =
path("ping") {
get {
complete("message" -> "pong")
}
}
}
Run Code Online (Sandbox Code Playgroud)
MyHttpService是一个扩展的自定义类,HttpService只包含实用程序方法.
这是测试规范:
import akka.actor.ActorRefFactory
import org.json4s.{DefaultFormats, Formats}
import org.scalatest.{FreeSpec, Matchers}
import spray.testkit.ScalatestRouteTest
class PingServiceSpec extends FreeSpec with PingService with ScalatestRouteTest with Matchers {
override implicit def actorRefFactory: ActorRefFactory = system
override implicit def json4sFormats: Formats = DefaultFormats
"Ping service" - {
"when calling GET /ping" - {
"should return 'pong'" in {
Get("/ping") ~> pingRoutes ~> check {
status should equal(200)
entity.asString should contain("pong")
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
每当我尝试运行测试时,都会收到以下错误:
could not find implicit value for parameter ta: PingServiceSpec.this.TildeArrow[spray.routing.RequestContext,Unit]
Get("/ping") ~> userRoutes ~> check {
^
Run Code Online (Sandbox Code Playgroud)
我做了些蠢事吗?任何形式的帮助将不胜感激!
编辑:虽然这可能看起来像这个问题的骗局,但事实并非如此.
该帖子提供的解决方案无效.