玩2项通过系统性能测试案例(Play 2 passing system properties to

2019-07-29 19:03发布

当执行“播放测试”,有没有办法在测试情况下使用的系统属性通过?

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中得到空值。

Answer 1:

1.2.4

试着play run -DtestDB=localdb --%test

我发现,在底部http://www.playframework.org/documentation/1.2.4/ids它指出, play test ,相当于play run --%test

2.0

尽量play -DtestDB=localdb test

该系统属性需要是命令。



文章来源: Play 2 passing system properties to test cases