lundi 30 mai 2016

Test for play controller with custom application.conf

I trying make simple controller test in play framework

public class AuthTest extends WithServer {

@Test
public void authByLoginErrorForm() {
    Map<String,String> data = new HashMap<>();
    data.put("username", "");
    data.put("password", "");

    Result result = routeAndCall(fakeRequest("POST", "/auth_by_login"), Helpers.DEFAULT_TIMEOUT);
    assertEquals(400, result.status());
}
}

In builds.sbt i set custom conf for test mode. He need for exclude creation db pool connection in test.

javaOptions in Test ++= Seq(
"-Dlogger.file=test/conf/logback.xml",
"-Xms512M",
"-Xmx1536M",
"-XX:MaxPermSize=384M",
"-XX:MaxMetaspaceSize=384M",
"-Dconfig.file=test/conf/application.conf"
)

After test running i getting error:

[error] Test controller.AuthTest.authByLoginErrorForm failed: java.lang.RuntimeException: java.lang.ClassNotFoundException: Routes, took 2.881 sec
[error]     at play.test.Helpers.routeAndCall(Helpers.java:293)
[error]     at controller.AuthTest.authByLoginErrorForm(AuthTest.java:28)
[error]     ...
[error] Caused by: java.lang.ClassNotFoundException: Routes
[error]     at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[error]     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[error]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
[error]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[error]     at play.test.Helpers.routeAndCall(Helpers.java:289)
[error]     ... 37 more
[error] Failed: Total 1, Failed 1, Errors 0, Passed 0
[error] Failed tests:
[error]     controller.AuthTest

i copy routes file to test/conf directory (near with) application.conf, but got same error.

Aucun commentaire:

Enregistrer un commentaire