1
ここでは、単純再生再生ビューテストを行います。ビューテンプレートでは、flash.get()を通してセッション情報にアクセスしようとしています。 しかし、メッセージでテストに失敗しましたThere is no HTTP Context available from here.
junitテストコンテキストで、テスト済みのアプリケーションに偽のセッションデータを追加するにはどうすればよいですか? WithServer
を使用して再生2.5レンダービューテスト、フラッシュメッセージへのアクセス
public class ApplicationTest extends WithServer {
private FormFactory formFactory() {
return app.injector().instanceOf(FormFactory.class);
}
@Test
public void renderTemplate() {
Content html;
session().put("session","123");
html = index.render(formFactory().form(Auth.Login.class));
assertTrue(contentAsString(html).contains("Hello"));
}
}
Test ApplicationTest.renderTemplate failed: java.lang.RuntimeException: There is no HTTP Context available from here., took 0.544 sec
at play.mvc.Http$Context.current(Http.java:57)
at play.mvc.Http$Context$Implicit.flash(Http.java:307)
at views.html.index_Scope0$index$$anonfun$apply$1.apply(index.template.scala:39)
at views.html.index_Scope0$index$$anonfun$apply$1.apply(index.template.scala:38)
at views.html.helper.form_Scope0$form.apply(form.template.scala:35)
at views.html.index_Scope0$index.apply(index.template.scala:38)
at views.html.index_Scope0$index.render(index.template.scala:141)
at views.html.index.render(index.template.scala)
at ApplicationTest.renderTemplate(ApplicationTest.java:37)