当执行“播放测试”,有没有办法在测试情况下使用的系统属性通过?
String testDB = System.getProperties().getProperty("testDB");
Map<String, String> conf = new HashMap<String, String>();
if (testDB.equals("localdb")) {
conf.put("db.default.driver", "org.postgresql.Driver");
conf.put("db.default.url", "postgres://postgres:postgres@localhost/db");
} else if (testDB.equals("memorydb")) {
conf.put("db.default.driver", "org.h2.Driver");
conf.put("db.default.url", "jdbc:h2:mem:play-test");
} else {
conf.put("db.default.driver", "org.postgresql.Driver");
conf.put("db.default.url", "postgres://postgres:postgres@localhost/db");
}
running(fakeApplication(conf), new Runnable() {
public void run() {
int preRowCount = Info.find.findRowCount();
Info info = new Info("key");
info.save();
assertThat(Info.find.findRowCount()).isEqualTo(preRowCount+1);
info.delete();
}
});
我想“玩测试-DtestDB =的LocalDB”,但testdb中得到空值。