特别是对于测试用例,我希望将测试数据库分开,以便测试用例不会干扰开发或生产数据库。
有哪些分离开发、测试和生产环境的良好做法?
EDIT1:一些背景
在Ruby On Rails 中,不同的环境有不同的配置文件。玩也一样! 2还支持那个?
或者,我是否必须编写配置文件,然后编写一些胶水代码来选择适当的配置文件?
此刻如果我运行 sbt test
它使用开发数据库(在 conf/application.conf 中配置为“默认”)。但是我希望 Play!2 使用不同的测试数据库。
EDIT2: Play 提供的命令
为了玩! 2 框架,我观察到了这一点。
$ help play
Welcome to Play 2.2.2!
These commands are available:
-----------------------------
...OUTPUT SKIPPED...
run <port> Run the current application in DEV mode.
test Run Junit tests and/or Specs from the command line
start <port> Start the current application in another JVM in PROD mode.
...OUTPUT SKIPPED...
“测试”、“开发”和“生产”实例有三个明确定义的命令,它们是:
-
test
:这将运行测试用例。所以它应该自动选择test
配置。 -
run <port>
:这会运行development
指定port
上的实例.所以这个命令应该自动选择development
配置。 -
start <port>
:这会运行production
指定port
上的实例.所以这应该会自动选择production
配置。
但是,所有这些命令都会选择 conf/application.conf
中提供的值.我觉得这里有一些空白需要填补。
如果我说错了请指正
EDIT3:最佳方法是使用 Global.scala
此处描述:How to manage application.conf in several environments with play 2.0?
最佳答案
好的做法是将应用程序的单独实例保存在单独的文件夹中并同步它们,即通过 git repo。
当你想保留单个实例时,你可以使用 alternative configuration file对于每个环境。
关于scala - 如何在 Play! 中保持单独的开发、测试和生产数据库2 框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23738647/