I have play framework application v2.2 that use Mongo Database (using play-jongo). I have some testing unit class in /test folder. However if I run the unit class using test
command or run directly from eclipse, there is no data found at all from Mongo DB, but if I run the application normally, I can see the data. I have used Helpers.faceApplication()
method but still no data at all.
Here is the unit test code:
@Test
public void test1() {
Helpers.running(Helpers.fakeApplication(), new Runnable() {
@Override
public void run() {
//MyUser is the mongo entity
MyUser myUser = MyUser.findById("123");
if (myUser != null) {
Logger.info("User ID: " + myUser.id);
} else {
Logger.info("User is NULL"); //it always get here
}
}
});
}
The myUser is always returned null if I run the test unit.
I have feeling that the Helpers.fakeApplication doesn't read the /conf/applicaton.conf
so it doesn't connect to mongo db.
Anyone know how to connect the play to mongo db when running in test unit?