We are trying to write tests for our views, but some of them require session variables for proper visualization. Here's what the standard test looks like:
@Test public void indexTest() { running(fakeApplication(), new Runnable() { public void run() { Content html = views.html.index.render(loginForm); assertThat(contentType(html)).isEqualTo("text/html"); assertThat(contentAsString(html)).contains("log in"); } }); }
loginForm is the layout we declared in the test class.
However, when we try to run this test, we get the following error:
"HTTP context is not available here"
We tried to use testServer and tried to get the HTTP context from requests to this server, but to no avail.
Thanks: -)
Edit @nico_ekito
This is the code surrounding my loginForm:
Form<Login> loginForm = Controller.form(Login.class);
However, I believe that the problem is in calling the controller, because the view does not use any session properties. The authenticate () method (in the controller that is being rendered, I believe when the form is submitted to the view), however, uses sessions.
source share