2

我正在使用具有交叉编译设置的 build.sbt,基本上是“使用 scala-js 示例”的改编版本,并且在为我的测试设置干净的设置时遇到了一些麻烦。具体来说,在运行我的服务器测试时,我的客户端测试也会被执行(这是我想要避免的)。

我按照Cannot get uTest中的说明查看我的测试 并添加

libraryDependencies += "com.lihaoyi" %%% "utest" % "0.3.0"

出于某种原因,我的测试在我添加之前没有执行

testFrameworks += new TestFramework("utest.runner.Framework")

到每个项目定义。也不加

"com.lihaoyi" %% "utest" % "0.3.1" % "test"

到服务器端触发一系列

未找到:object utest [error] import utest._ -style 错误。

在我的印象中,如果有一个干净的设置,我根本不需要添加这些额外的设置。这是我的 sbt 文件:

import sbt.Project.projectToRef
lazy val clients = Seq(client)
lazy val scalaV = "2.11.7"

lazy val server = (project in file("server")).settings(
  scalaVersion := scalaV,
  scalaJSProjects := clients,
  pipelineStages := Seq(scalaJSProd/*, gzip*/),
  resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases",
  libraryDependencies ++= Seq(
    "com.vmunier" %% "play-scalajs-scripts" % "0.3.0",
    "be.doeraene" %% "scalajs-pickling-play-json" % "0.4.0"
  ),
  testFrameworks += new TestFramework("utest.runner.Framework")
).enablePlugins(PlayScala).
  aggregate(clients.map(projectToRef): _*).
  dependsOn(sharedJvm)

lazy val client = (project in file("client")).settings(
  scalaVersion := scalaV,
  persistLauncher := true,
  persistLauncher in Test := false,
  libraryDependencies ++= Seq(
    "org.scala-js" %%% "scalajs-dom" % "0.8.0"
  ),
  testFrameworks += new TestFramework("utest.runner.Framework")
).enablePlugins(ScalaJSPlugin, ScalaJSPlay).
  dependsOn(sharedJs)

lazy val shared = (crossProject.crossType(CrossType.Pure) in file("shared")).
  settings(scalaVersion := scalaV,
    libraryDependencies ++= Seq(
    "com.lihaoyi" %%% "utest" % "0.3.1",
    "be.doeraene" %%% "scalajs-pickling-core" % "0.4.0",
    "com.lihaoyi" %%% "pprint" % "0.3.6"
    ),
    testFrameworks += new TestFramework("utest.runner.Framework")
  ).

  jsConfigure(_ enablePlugins ScalaJSPlay)
lazy val sharedJvm = shared.jvm
lazy val sharedJs = shared.js

// loads the Play project at sbt startup
onLoad in Global := (Command.process("project server", _: State)) compose (onLoad in Global).value

这里是我的问题的总结:

  • 当我运行客户端/测试时,只执行客户端测试
  • 运行 play-with-scalajs-example/test 时,执行客户端 + 共享测试
  • 奇怪的是,在运行服务器/测试我的服务器和客户端测试时

我如何将我的项目设置修改为

  • 运行 server/test 时找到我的服务器测试
  • 运行 play-with-scalajs-example/test 时运行所有测试
  • 并且还包括运行服务器/测试或客户端测试时的共享测试?

在另一个节点上,有没有办法禁用 scalatest?它导致一个相当不可读的测试输出:

[info] 1/2     TestSimpleServerSuite.absolutely simple test on the server side          Success
[info] 2/2     TestSimpleServerSuite            Success
[info] utest
[info] -----------------------------------Results-----------------------------------
[info] 
[info] 
[info] Tests: 0
[info] Passed: 0
[info] Failed: 0
[info] Passed: Total 2, Failed 0, Errors 0, Passed 2
[info] 1/2     TestSimpleClientSuite.absolutely simple test on the client side          Success
[info] 2/2     TestSimpleClientSuite            Success
[info] 1/2     SimpleClient.TestSimpleClientSuite.absolutely simple test on the client side             Success
[info] 2/2     SimpleClient.TestSimpleClientSuite               Success
[info] ScalaCheck
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] ScalaTest
[info] Run completed in 1 second, 751 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[info] utest
[info] -----------------------------------Results-----------------------------------
[info] SimpleClient.TestSimpleClientSuite               Success
[info]     absolutely simple test on the client side            Success
[info] TestSimpleClientSuite            Success
[info]     absolutely simple test on the client side            Success
[info] 
[info] Tests: 4
[info] Passed: 4
[info] Failed: 0
[info] Passed: Total 4, Failed 0, Errors 0, Passed 4
[success] Total time: 11 s, completed 16.10.2015 03:25:59

非常感谢和亲切的问候

4

1 回答 1

1

sjrd关于删除聚合的评论为我指明了正确的道路。删除它停止

server/test

从执行服务器和客户端测试。正如sjrd 所指出的,所使用的聚合函数还运行在客户端上的服务器上运行的每个任务。

聚合意味着在聚合项目上运行任务也会在聚合项目上运行。(参见:sbt 文档

因为我还想在运行测试时在客户端和服务器项目上运行共享测试,所以我修改了服务器项目定义的聚合函数,并在客户端项目定义中添加了一个额外的聚合。:

服务器定义:

lazy val server = (project in file("server")).settings(
  scalaVersion := scalaV,
  scalaJSProjects := clients,
  pipelineStages := Seq(scalaJSProd/*, gzip*/),
  resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases",
  libraryDependencies ++= Seq(
    "com.vmunier" %% "play-scalajs-scripts" % "0.3.0",
    "be.doeraene" %% "scalajs-pickling-play-json" % "0.4.0",
    "com.lihaoyi" %% "utest" % "0.3.1" % "test"
  ),
  testFrameworks += new TestFramework("utest.runner.Framework")
).enablePlugins(PlayScala).
  /*
   * Executes shared tests compiled to JVM with server/test
   */
  aggregate(projectToRef(sharedJvm)). // Former: aggregate(clients.map(projectToRef): _*). before
  dependsOn(sharedJvm)

客户端定义:

lazy val client = (project in file("client")).settings(
  scalaVersion := scalaV,
  persistLauncher := true,
  persistLauncher in Test := false,
  libraryDependencies ++= Seq(
    "org.scala-js" %%% "scalajs-dom" % "0.8.0"
  ),
  testFrameworks += new TestFramework("utest.runner.Framework")
).enablePlugins(ScalaJSPlugin, ScalaJSPlay).
  /*
   * Executes shared tests compiled to JS with client/test
   */
  aggregate(projectToRef(sharedJs)).
  dependsOn(sharedJs)

当使用 play-with-scalajs-example/test 运行测试时,现在运行所有测试,包括为 JS 和 JVM 分别编译的共享测试。

至于必须明确包含 utest 依赖项,似乎客户端和服务器项目不是从 crossProject 派生的,因此是断开连接的——将寻找一种更好的处理方法。

于 2015-10-17T19:16:47.087 回答