Why not use selenium ?
See the last part of the help : http://www.playframework.com/documentation/2.0/JavaFunctionalTest
Question
In the latest documentation, this template test is given as an example.
@Test
public void renderTemplate() {
Content html = views.html.index.render("Coco");
assertThat(contentType(html)).isEqualTo("text/html");
assertThat(contentAsString(html)).contains("Coco");
}
But how am I supposed to run this? I tried it on its own, inside the run() method on a fake server, a real server, along side an actual running server, and I always get this error.
[error] Test ApplicationTest.testInServer failed: java.lang.RuntimeException: There is no HTTP Context available from here.
There are literally two pages on testing in the documentation and I have no idea how to actually run any of these tests. Is there an example class anywhere that doesn't use deprecated methods (things have changed since Play 1 and most things don't work any more).
Solution 3
Why not use selenium ?
See the last part of the help : http://www.playframework.com/documentation/2.0/JavaFunctionalTest
OTHER TIPS
You need to setup the Http Context first.
Example with Mockito:
@Test
public void indexTest() {
//setup HTTP Context
Http.Context context = Mockito.mock(Http.Context.class);
//mocking flash session, request, etc... as required
Http.Flash flash = Mockito.mock(Http.Flash.class);
when(context.flash()).thenReturn(flash);
Http.Context.current.set(context);
//run your test
Content html = views.html.index.render("Coco");
assertThat(contentType(html)).isEqualTo("text/html");
assertThat(contentAsString(html)).contains("Coco");
}
Run "play test" from your command-line. That will runs all the tests in the test folder.