spray.testkit的使用

具体

 

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.ActorRefFactory
import org.specs2.mutable.Specification
import spray.testkit.Specs2RouteTest
import spray.routing.HttpService
import 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值