scala - 如何在 Play! 中保持单独的开发、测试和生产数据库2 框架?

标签 scala testing playframework

特别是对于测试用例,我希望将测试数据库分开,以便测试用例不会干扰开发或生产数据库。

有哪些分离开发、测试和生产环境的良好做法?

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/

相关文章:

testing - tfs 2012中的测试影响分析

python - 测试具有某些代码的函数依赖于在本地测试期间不可用的服务?

scala - 如何重载scala函数的应用方法

scala - Spark 1.5.2 : Filtering a dataframe in Scala

Scala 2.12 使用 Java 1.8;如果无法升级到Java 1.8怎么办?

python - 单元测试中未调用 load_tests()

java - 升级到 2.x 时,org.refcodes.console.ConsoleSugar 中缺少 switsh 和 helpSwitch 方法

java - 使用 JsonView 将 POJO 转换为 JsonNode

scala - SBT:更新项目引用

playframework - 使用 Slick 3.0 在同一事务中进行多次插入