When executing ‘play test’, is there a way to pass in system properties to be used at test cases?
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();
}
});
I tried ‘play test -DtestDB=localdb’, but got null value in testDB.
1.2.4
Try
play run -DtestDB=localdb --%testI found that at the bottom of http://www.playframework.org/documentation/1.2.4/ids where it states that
play testis equivalent toplay run --%test.2.0
Try
play -DtestDB=localdb testThe system property needs to be before the command.