我正在使用具有交叉编译设置的 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
非常感谢和亲切的问候