sbt play cross build project setup: uTest runner doesn't separate client/server projects 正确
sbt play cross build project setup: uTest runner doesn't seperate client/server projects correctly
我正在使用 build.sbt,它具有交叉编译设置,基本上是“Play with scala-js example”的改编版本,并且在为我的测试获得干净的设置时遇到了一些麻烦。具体来说,当 运行 连接我的服务器测试时,我的客户端测试也会被执行(这是我想避免的事情)。
我按照 的说明进行操作
并添加
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.3.0"
由于某种原因,我的测试在添加
之前没有执行
testFrameworks += new TestFramework("utest.runner.Framework")
每个项目定义。也不加
"com.lihaoyi" %% "utest" % "0.3.1" % "test"
到服务器端触发一系列
not found: object utest [error] import utest._
-style errors.
根据我的印象,如果有一个干净的设置,我根本不需要添加这些额外的设置。这是我的 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
这里是我的问题总结:
- 当我 运行 client/test 时,只执行客户端测试
- 当运行宁play-with-scalajs-example/test时,执行客户端+共享测试
- 奇怪的是,当 运行ning server/test 我的服务器和客户端测试被执行时
如何将我的项目设置修改为
- 在 运行ning server/test
时找到我的服务器测试
- 运行在运行宁play-with-scalajs-example/test
时宁所有测试
- 并且在 运行ning server/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
致谢和亲切的问候
sjrd 关于删除聚合的评论为我指明了正确的道路。
删除它停止了
server/test
从执行服务器和客户端测试。正如 sjrd 指出的那样,聚合函数还使用 运行 客户端服务器上 运行 的每个任务。
Aggregation means that running a task on the aggregate project will
also run it on the aggregated projects.
(See: sbt doc)
由于我还想 运行 在 运行ning 测试时在客户端和服务器项目上共享测试,我修改了服务器项目定义的聚合函数,并向客户端添加了一个额外的聚合项目定义。 :
服务器定义:
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)
当 运行ning 使用 play-with-scalajs-example/test 进行测试时,现在 运行s 所有测试,包括为 JS 和 JVM 单独编译的共享测试。
至于必须显式包含 utest 依赖项,客户端和服务器项目似乎不是从 crossProject 派生的,因此是断开连接的 - 将寻找更好的处理方法。
我正在使用 build.sbt,它具有交叉编译设置,基本上是“Play with scala-js example”的改编版本,并且在为我的测试获得干净的设置时遇到了一些麻烦。具体来说,当 运行 连接我的服务器测试时,我的客户端测试也会被执行(这是我想避免的事情)。
我按照
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.3.0"
由于某种原因,我的测试在添加
之前没有执行testFrameworks += new TestFramework("utest.runner.Framework")
每个项目定义。也不加
"com.lihaoyi" %% "utest" % "0.3.1" % "test"
到服务器端触发一系列
not found: object utest [error] import utest._ -style errors.
根据我的印象,如果有一个干净的设置,我根本不需要添加这些额外的设置。这是我的 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
这里是我的问题总结:
- 当我 运行 client/test 时,只执行客户端测试
- 当运行宁play-with-scalajs-example/test时,执行客户端+共享测试
- 奇怪的是,当 运行ning server/test 我的服务器和客户端测试被执行时
如何将我的项目设置修改为
- 在 运行ning server/test 时找到我的服务器测试
- 运行在运行宁play-with-scalajs-example/test 时宁所有测试
- 并且在 运行ning server/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
致谢和亲切的问候
sjrd 关于删除聚合的评论为我指明了正确的道路。 删除它停止了
server/test
从执行服务器和客户端测试。正如 sjrd 指出的那样,聚合函数还使用 运行 客户端服务器上 运行 的每个任务。
Aggregation means that running a task on the aggregate project will also run it on the aggregated projects. (See: sbt doc)
由于我还想 运行 在 运行ning 测试时在客户端和服务器项目上共享测试,我修改了服务器项目定义的聚合函数,并向客户端添加了一个额外的聚合项目定义。 :
服务器定义:
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)
当 运行ning 使用 play-with-scalajs-example/test 进行测试时,现在 运行s 所有测试,包括为 JS 和 JVM 单独编译的共享测试。
至于必须显式包含 utest 依赖项,客户端和服务器项目似乎不是从 crossProject 派生的,因此是断开连接的 - 将寻找更好的处理方法。