问题描述
我正在尝试使用喷涂路线,并想使用Spray-TestKit对其进行测试。我正在使用的
:
-Scala 2.10.3
-Akka 2.3.3
-Spray 1.3.1
I am trying to use spray route and want to test it with Spray-TestKit.I am using :- Scala 2.10.3- Akka 2.3.3- Spray 1.3.1
我创建了一个扩展HttpService的特征,并在其中定义了一条路由:
I create a trait extending HttpService, where I define a route :
trait MyService extends HttpService with CoreAccess {
import greentee.am.endpoint.tsmsp.tsmSPJsonSupport._
val myRoute = {
path("resources"/"ping") {
get {
complete(OK, "pong")
}
}
}
}
我删除了部分不相关的路线。
CoreAccess是一个扩展Actor的特征,因为在该特征中我有一些方法可以访问ActorSystem。 (我不知道谁不从特征中获取ActorSelection而不扩展其actor)
I deleted part of the route which was not relevant.CoreAccess is a trait extending Actor, because I have methods in that trait access the ActorSystem. (I don't know who to retrieve ActorSelection from a trait without it extending an actor)
然后我创建一个测试规范
Then I create a test Specification
import MyService
import org.specs2.mutable.Specification
import spray.testkit.Specs2RouteTest
import spray.http.StatusCodes._
class RegistrationRouteSpecification extends Specification with Specs2RouteTest with MyService {
def actorRefFactory = system
"The EndPoint " should {
"return Pong to a Get request to the ping" in {
Get("/resources/ping") ~> myRoute ~> check {
status === OK
responseAs[String] === "pong"
}
}
}
}
当我尝试执行测试时,出现以下编译错误:
When I try to execute the test, I get the following compilation error:
[info] Compiling 1 Scala source to /Users/IdeaProjects/endpoint/target/scala-2.10/test-classes...
[error] /Users/IdeaProjects/endpoint/src/test/scala/RegistrationRouteSpecification.scala:19: could not find implicit value for parameter ta: RegistrationRouteSpecification.this.TildeArrow[spray.routing.RequestContext,Unit]
[error] Get("/resources/ping") ~> myRoute ~> check {
[error] ^
[error] one error found
推荐答案
我回答了我自己的问题。
我更正了Build.scala以使用以下行:
I answer my own question.I corrected my Build.scala to use the following lines:
val scalaCheck = "org.scalacheck" %% "scalacheck" % Versions.scalaCheckVersion % "test"
val scalaTest = "org.scalatest" %% "scalatest" % "2.2.0" % "test"
而不是使用简单的'%'并提供专用版本。
Instead of using a simple '%' and supplying a dedicated version.
这篇关于无法使用基本Spray-Testkit测试路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!