Play: Run tests with custom GuiceApplicationLoader

I have a CustomApplicationLoader extends GuiceApplicationLoader in which I load the conf file. When I run tests in ApplicationSpec, the values ​​taken from certain conf files are missing, which presumably means my CustomApplicationLoader was not executed.

Any idea how to pass CustomApplicationLoader to FakeApplication or any other approach for reading values ​​from conf files during tests? Or shouldn't it even work out of the box?

+3


source to share


1 answer


So, I found out that I can add a custom GuiceApplicationLoader by passing it as an argument to the WithApplicationLoader like this:



    @RunWith(classOf[JUnitRunner])
class ApplicationSpec extends Specification {

  "My component" should {

    "load environment specific conf values loaded in by CustomApplicationLoader" in new WithApplicationLoader(new CustomApplicationLoader) {
        ...
      }
    }

}

      

+3


source







All Articles