【问题标题】:How can I create an SBT task to test the scala code in Play Framework如何创建 SBT 任务来测试 Play Framework 中的 scala 代码
【发布时间】:2019-02-28 17:42:14
【问题描述】:

我正在使用IntelliJ 进行开发。我创建了一个 test 文件夹,其中包含我的 spec 文件。要测试specs,我右键单击项目目录并选择run->all tests

我想创建一个sbt 任务来测试代码。我知道我必须在build.sbt 中定义口味,但我不知道运行测试的命令。

在游戏中运行测试的命令是什么?文档说 (https://www.playframework.com/documentation/2.7.x/ScalaTestingWithScalaTest#Testing-your-application-with-ScalaTest)

You can run tests from the Play console. To run all tests, run test.。但我不知道如何玩控制台。

【问题讨论】:

    标签: intellij-idea playframework-2.6


    【解决方案1】:

    我很乐意接受更好的答案。到目前为止,我已经完成了以下工作,这似乎有效。基本上,要运行play 测试,我需要调用sbt testplay console 只是 sbt console 的包装。在我的build.sbt 中,我编写了以下任务。这些任务类似于转到cmdterminal 中的顶级项目目录并运行sbt test

    在 build.sbt 中

    def runBackendTests(implicit dir:File):Int = runScript("sbt test")
    
    lazy val `backend-test` = taskKey[Unit]("Run Backend tests when testing application.")
    
    `backend-test` := {
      implicit val backendRoot = baseDirectory.value //this should be top level project directory. The tests are in test directory in this directory
      println("backend root is ",backendRoot)
      if(runBackendTests != 0) throw new Exception("Backend tests failed")
    }
    

    【讨论】:

      猜你喜欢
      • 2017-08-25
      • 2019-04-20
      • 1970-01-01
      • 2018-08-13
      • 1970-01-01
      • 2012-07-02
      • 2015-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多