spray.testkit的使用

来源:互联网 发布:fastjson map转json 编辑:程序博客网 时间:2024/05/22 10:54

具体

 

http://spray.io/documentation/1.2.3/spray-testkit/

 

依赖

name:="demo9"transitiveClassifiers := Seq("sources", "javadoc")resolvers += "spray repo" at "http://repo.spray.io"libraryDependencies ++= Seq(  "com.typesafe.akka" %  "akka-actor_2.2.5"      % "2.3.12" withSources() withJavadoc(),  "com.typesafe.akka" %  "akka-testkit_2.2.5"    % "2.3.12" withSources() withJavadoc(),  "org.scalatest"   %  "scalatest_2.10"        % "2.2.2"  withSources() withJavadoc(),  "org.specs2"      %% "specs2"      % "1.12.3" withSources() withJavadoc(),  "com.jsuereth"      %% "scala-arm"             % "1.3",  "org.json4s"        %% "json4s-native"         % "3.2.10" withSources() withJavadoc(),  "org.json4s"        %% "json4s-jackson"        % "3.2.10" withSources() withJavadoc(),  "io.spray"          %  "spray-can"             % "1.2.3"  withSources() withJavadoc(),  "io.spray"          %  "spray-http"            % "1.2.3"  withSources() withJavadoc(),  "io.spray"          %  "spray-httpx"           % "1.2.3"  withSources() withJavadoc(),  "io.spray"          %  "spray-util"            % "1.2.3"  withSources() withJavadoc(),  "io.spray"          %  "spray-testkit"         % "1.2.3"  withSources() withJavadoc(),  "io.spray"          %  "spray-routing"         % "1.2.3"  withSources() withJavadoc()  )


主要是

 


spray-http (with ‘provided’ scope)
spray-httpx (with ‘provided’ scope)
spray-routing (with ‘provided’ scope)
spray-util
akka-actor 2.2.x (with ‘provided’ scope, i.e. you need to pull it in yourself)
akka-testkit 2.2.x (with ‘provided’ scope, i.e. you need to pull it in yourself)
scalatest (with ‘provided’ scope, for the ScalatestRouteTest)
specs2 (with ‘provided’ scope, for the Specs2RouteTest)

编写的格式

 

 

REQUEST ~> ROUTE ~> check {  ASSERTIONS}


大写的必须的

例如

Put("/34") ~> sealRoute(smallRoute) ~> check {}


必须提供一个

  val actorRefFactory: ActorRefFactory = system

作为  service actor or the service test

 

 

一个基本的例子

import akka.actor.ActorRefFactoryimport org.specs2.mutable.Specificationimport spray.testkit.Specs2RouteTestimport spray.routing.HttpServiceimport spray.http.StatusCodes._class AppTest extends Specification with Specs2RouteTest with HttpService{  val actorRefFactory: ActorRefFactory = system  val smallRoute = get{    pathSingleSlash{      complete{        <html>          <body>            <h1>Say hello to <i>spray</i>!</h1>          </body>        </html>      }    } ~ path("ping"){        complete("PONG")    }  }  "The service" should {    "return a greeting for GET requests to the root path" in {      Put("/34") ~> sealRoute(smallRoute) ~> check {        //handled must beFalse        //responseAs[String] must contain("Say hello")        status === MethodNotAllowed        responseAs[String] === "HTTP method not allowed, supported methods: GET"      }    }  }}



 

 

 

 

 

 

 

 

0 0
原创粉丝点击