【发布时间】:2013-10-01 02:38:11
【问题描述】:
我正在尝试编写一个 Specs2 测试用例来测试 sn-ps。 我的 sn-p 看起来像这样:
class RegisterTest extends Specification {
val testurl = "http:/html/register?username=liftvalues"
val testSession = MockWeb.testS(testurl) { S.session }
def inSession[T](a: => T): T = S.initIfUninitted(testSession) { a }
def is = s2""" example1 $e1 """
val html = <form><input name="username" value="liftvalues"></input></form>
def e1 = {
inSession{
register(html)
}
}
def register(in:NodeSeq):Result = {
val username = S.param("username") //Here we are getting "Empty Value" for the S object.
username === "liftvalues" and UserSchemaTest.registerData("data")
}
}
此测试失败,因为 S.param 是 Empty。我应该怎么做才能向 sn-p 提供模拟请求?
到目前为止,我已经看过Unit Testing Snippets With A Logged In User 和Mocking HTTP Requests,但我不明白如何实现我的目标。
【问题讨论】: