且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Play2.0中操纵会话,请求和响应进行测试

更新时间:2023-08-18 09:42:16

可以执行类似于play1.x的方法.中心点是Context.此外,您必须创建一个DummyRequest来实现所需的方法.然后可以创建以下内容

It's possible to do it similar to play1.x. The central point is the Context. Furthermore you must create a DummyRequest which implements the methods you need. Then it's possible to create the following

final Request request = new DummyRequest();
Context.current.set(new Context(request, new HashMap <String, String>(), 
        new HashMap <String, String>()));

在测试中,您可以获得Context.current().session()Context.current().response()Context.current().request().

in your test you can get Context.current().session(), Context.current().response() or Context.current().request().

您可以在此处看到 查看全文