如何创建SBT任务以在Play Framework中测试scala代码

问题描述 投票:0回答:1

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

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

在运行中运行测试的命令是什么?文件说(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个回答
0
投票

我很乐意接受更好的答案。到目前为止,我已经完成了以下工作。基本上,要运行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")
}
© www.soinside.com 2019 - 2024. All rights reserved.