播放2个传递系统属性以测试案例

时间:2012-06-06 22:57:54

标签: playframework-2.0

执行'play test'时,有没有办法传入系统属性以便在测试用例中使用?

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();
    }
});

我试过'play test -DtestDB = localdb',但在testDB中得到了null值。

1 个答案:

答案 0 :(得分:6)

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

系统属性需要在命令之前。