相关疑难解决方法(0)

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

执行'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();
    }
});
Run Code Online (Sandbox Code Playgroud)

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

playframework-2.0

2
推荐指数
1
解决办法
1951
查看次数

标签 统计

playframework-2.0 ×1