Play 2.4: How do I disable routes file loading during unit tests?

前端 未结 2 1056
旧巷少年郎
旧巷少年郎 2021-02-04 08:41

Background: I am using Play 2.4 (Java) with InjectedRoutesGenerator and a Guice module to configure various dependencies. But during unit tests, the FakeApplica

2条回答
  •  遥遥无期
    2021-02-04 09:17

    If you want to just load no routes at all, here's a trait you could mix in to your test class if you're using Scala, Guice and ScalaTest. This is working with Play 2.5. I've also shown how you could disable filters, since those are related to routing.

    I know this is a little different from the ask on Java and Play 2.4, but this might be helpful to people as I got to this question trying to achieve something very similar.

    trait DisabledRouting extends PlaySpec with OneAppPerSuite {
    
      override def fakeApplication(): Application = {
        configureApplication(new GuiceApplicationBuilder()
          .router(Router.empty)
          .configure("play.http.filters" -> "play.api.http.NoHttpFilters"))
          .build()
      }
    
      /** Override to add additional configuration on top of disabled routing */
      def configureApplication(appBuilder: GuiceApplicationBuilder): GuiceApplicationBuilder = appBuilder
    
    }
    

提交回复
热议问题