播放2个通过系统的属性以测试用例 [英] Play 2 passing system properties to test cases
本文介绍了播放2个通过系统的属性以测试用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在执行播放测试"时,是否可以传递用于测试用例的系统属性?
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();
}
});
我尝试了'play test -DtestDB = localdb',但是testDB中的值为空.
I tried 'play test -DtestDB=localdb', but got null value in testDB.
推荐答案
1.2.4
尝试play run -DtestDB=localdb --%test
我发现位于 http://www.playframework.org/documentation的底部/1.2.4/ids ,其中指出play test
等同于play run --%test
.
I found that at the bottom of http://www.playframework.org/documentation/1.2.4/ids where it states that play test
is equivalent to play run --%test
.
尝试play -DtestDB=localdb test
系统属性必须在命令之前.
The system property needs to be before the command.
这篇关于播放2个通过系统的属性以测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文