It seems that when a public static method of a controller calls another public static method of the same controller explicitly (with a Java call), Play! doesn’t know to just execute the code or redirect in functional tests.
If I have:
public class ApplicationTest extends FunctionalTest {
@Test
public void testProvesThatFunctionalTestsDoesntCallControllerMethods() {
Response response = GET("/");
assertEquals("", getContent(response));
}
@Test
public void testProvesThatCallingItDirectlyWorksAsExpected() throws Exception {
Response response = GET("/another");
assertEquals("ok!", getContent(response));
}
}
And:
public class Application extends Controller {
public static void index() {
another();
}
public static void another() {
renderText("ok!");
}
}
But if I run play run or play start and call “/” in my web browser then it returns “ok!”, shouldn’t FunctionalTest work exactly like running it in production or as if the real server? It pushes me to avoid functional test or have a huge manual setup and dependency of a pre-running web server, that’s not cool.
Thanks in advance.
In your browser, when you call “/” it returns “ok” but not on the first response. It firsts return a redirect (302) and then returns a 200 (ok).
In your functional test, it is the same, You have to do something like