我正在尝试编写一个 Specs2 测试用例来测试这些片段。我的片段看起来像这样:
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
is Empty
。我应该怎么做才能提供带有模拟请求的代码段?
到目前为止,我已经查看了具有登录用户 和模拟 HTTP 请求的单元测试片段,但我不明白如何实现我的目标。