Scala sbt播放交叉构建项目设置:uTest runner不';t正确分离客户端/服务器项目

Scala sbt播放交叉构建项目设置:uTest runner不';t正确分离客户端/服务器项目,scala,sbt,scala.js,utest,Scala,Sbt,Scala.js,Utest,我正在使用一个build.sbt,它有交叉编译设置,基本上是“”的一个改编版本,并且在为我的测试获得一个干净的设置时遇到了一些困难。具体地说,当运行服务器测试时,我的客户机测试也会被执行(这是我想要避免的) 我听从了老师的指示 并补充说 libraryDependencies+=“com.lihaoyi”%%“utest”%%“0.3.0” 由于某种原因,我的测试直到添加 testFrameworks+=新的TestFramework(“utest.runner.Framework”) 每个项目

我正在使用一个build.sbt,它有交叉编译设置,基本上是“”的一个改编版本,并且在为我的测试获得一个干净的设置时遇到了一些困难。具体地说,当运行服务器测试时,我的客户机测试也会被执行(这是我想要避免的)

我听从了老师的指示 并补充说

libraryDependencies+=“com.lihaoyi”%%“utest”%%“0.3.0”

由于某种原因,我的测试直到添加

testFrameworks+=新的TestFramework(“utest.runner.Framework”)

每个项目的定义。也没有添加

“com.lihaoyi”%%“utest”%%“0.3.1”%”测试

到服务器端触发一系列

未找到:对象utest[错误]导入utest_ -样式错误

给我的印象是,如果有一个干净的设置,我根本不需要添加这些额外的设置。这是我的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示例/测试时,将执行客户端+共享测试
  • 奇怪的是,当运行服务器/测试时,会执行我的服务器和客户端测试
如何将项目设置修改为

  • 运行服务器/测试时查找我的服务器测试
  • 使用scalajs示例/测试运行play时运行所有测试
  • 在运行服务器/测试或客户端测试时,是否还包括共享测试
在另一个节点上,有没有办法禁用scalatest?这会导致无法读取的testoutput:

[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
非常感谢大家的好意

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

server/test
从执行服务器和客户端测试。如前所述,所使用的聚合函数还运行客户端服务器上运行的每个任务

聚合意味着在聚合项目上运行任务将 还可以在聚合项目上运行它。 (见:)

由于我还希望在运行测试时同时在客户端和服务器项目上运行共享测试,因此我修改了服务器项目定义的聚合函数,并在客户端项目定义中添加了一个额外的聚合:

服务器定义:

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派生的,因此是断开连接的-将寻找更好的处理方法。

删除
聚合(clients.map(projectToRef):*)。
。这件事明确地要求sbt,每当您在
服务器上运行任务时,它也会在
客户端上运行相同的任务。删除它确实做到了这一点,我最终修改了它,在运行服务器/测试或客户机测试时添加了共享测试。