我尝试在PlayFramework 2.3.8中执行一些JUnit测试我希望在内存数据库中执行此测试,以便保持“真实”数据库不变。 这就是我所做的:
public class SaveToolsTest extends WithApplication{
@Before
public void startApp(){
// Start the app in the in memory database.
Map<String, String> settings = new HashMap<String, String>();
settings.put("db.default.url", "jdbc:h2:mem:play");
settings.put("db.default.user", "");
settings.put("db.default.password", "");
app = Helpers.fakeApplication(settings);
Helpers.start(app);
}
@Test
public void saveUser(){
User user = createUser();
// Save the user into DB.
Ebean.save(user);
// Test if user != null
assertNotNull(user);
assertThat(user.id).isNotNull();
}
但通过这样做,我将测试连接到实际的数据库。 如何将其连接到内存数据库?