title: Scala Play application integration tests with guice context
body: <p>I'm new to play framework and have limited experience with scala. Using <code>play framework 2.4</code> I'm trying to write full integrations tests where I want to call controller, and using in-memory db retrieve data from it. I'm using <code>scalatest-plus</code> together with <code>scalatest</code>. I have read about play unit tests in play documentation and now trying to use <code>play.api.test.FakeApplication</code> but i cannot find a way to inject my guice module to this fake application. I'm ussing <code>OneAppPerSuite</code> trait I can override <code>FakeApplication</code> but cannot pass any <code>guice</code> module for injection. Here is <code>FakeApplication</code> source from:</p>
  
  <pre><code>case class FakeApplication(
    override val path: java.io.File = new java.io.File("."),
    override val classloader: ClassLoader = classOf[FakeApplication].getClassLoader,
    additionalPlugins: Seq[String] = Nil,
    withoutPlugins: Seq[String] = Nil,
    additionalConfiguration: Map[String, _ &lt;: Any] = Map.empty,
    withGlobal: Option[play.api.GlobalSettings] = None,
    withRoutes: PartialFunction[(String, String), Handler] = PartialFunction.empty) extends Application {
  
  private val app: Application = new GuiceApplicationBuilder()
    .in(Environment(path, classloader, Mode.Test))
    .global(withGlobal.orNull)
    .configure(additionalConfiguration)
    .bindings(
      bind[FakePluginsConfig] to FakePluginsConfig(additionalPlugins, withoutPlugins),
      bind[FakeRouterConfig] to FakeRouterConfig(withRoutes))
    .overrides(
      bind[Plugins].toProvider[FakePluginsProvider],
      bind[Router].toProvider[FakeRouterProvider])
    .build
  
    ....
  </code></pre>
  
  <p>So there is no way for me to pass custom module here.</p>
  
  <p>Here is how my test looks like:</p>
  
  <pre class="lang-scala prettyprint-override"><code>class UsersControllerTest extends PlaySpec with OneAppPerSuite {
  
      override implicit lazy val app = FakeApplication(additionalConfiguration = inMemoryDatabase())
  
      "Application " should {
  
         "work" in {
           val resp = route(FakeRequest(GET, "/api/users")).get
          }
      }
  </code></pre>
  
  <p>}</p>
  
  <p>And here is my controller I want to test:</p>
  
  <pre><code>class UserController @Inject()
    (userService: UserService)
    (implicit ec: ExecutionContext) extends Controller {
  
    def get = Action.async { implicit request =&gt; {
      // implementation
      }
    }
  </code></pre>
  
  <p>}</p>
  
  <p>Obviously my test now fail since it cannot find <code>UserService</code> instance.
  So my question is:</p>
  
  <ol>
  <li>How to properly write end2end integration tests with play using guice context</li>
  <li>Is it common to write such tests in play application, since I cannot find any decent examples or documentation of doing something like that. I used to write such tests in java web applications where integration tests load spring context, but can't find such examples in play.</li>
  </ol>
  
  <p>Thanks in advance.</p>