How can I specify a different config file for testing in Play 2.1

前端 未结 4 1470
误落风尘
误落风尘 2021-02-02 17:06

I would like to define different database connections for multiple test environments(Production, Staging, Development). After reading the post \"How do I specify a config file w

4条回答
  •  渐次进展
    2021-02-02 18:04

    we can mix the above solutions, to pass the config file as a parameter to sbt.
    This will be useful to integrate the test in CI pipeline

    First, in the Build.scala file

    val testOptions = "-Dconfig.file=conf/" + Option(System.getProperty("test.config")).getOrElse("application") + ".conf"
    
    val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
        javaOptions in Test += testOptions
    )
    

    Then, in the command line to run the test with integ.conf

    sbt -Dtest.config=integ test
    

    to use the default application.conf

    sbt test 
    

提交回复
热议问题