How to use in memory database with injected test with play java
Asked Answered
S

1

6

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.

Semester answered 5/6, 2015 at 9:11 Comment(4)
Did you look at this? playframework.com/documentation/2.4.x/JavaTestingWithDatabasesLisp
this chapter is if you want to test with a database but without an application. I want to start an application with the in-memory databaseSemester
Take a look at github.com/schaloner/deadbolt-2-java/blob/master/test-app/test/… - it might help get you started.Tonsillitis
in your example you are not using DI neither DI setup process so I don't understand how it can helps me in my caseSemester
E
5

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();
Electropositive answered 20/10, 2015 at 21:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.