Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use in memory database with injected test with play java

The play documentation about functional tests in java shows two modes

  • using fakeApplication to specify a custom configuration (in memory database in the example)
  • using dependency injection to configure the application

I would like to use dependency injection but I have to set custom configuration on application startup like the use of in memory database.

I cannot achieve to do that. I guess this has to be done in the guice builder but I don't know how.

like image 345
Seb Cesbron Avatar asked Jun 05 '15 09:06

Seb Cesbron


1 Answers

I am assuming you are using Guice for DI.

The discussion on issue 4809 on the framework's github repo should help on answering your question.

I was able to make it work using one of the solutions on the issue:

       new GuiceApplicationBuilder()
            .configure((Map) Helpers.inMemoryDatabase())
            .in(Mode.TEST)         
            .build();
like image 169
Raquel Guimarães Avatar answered Oct 25 '22 12:10

Raquel Guimarães