编辑:我找到了解决方案。杀死终端似乎可以解决问题。我猜它不会在计算机重新启动时终止。 但是我仍然不知道问题出在哪里。
我注意到 scalatest 突然变得更慢开始测试。 我删除了所有测试,只留下一个,简单地测试 true。 这是我得到的(使用 sbt)
MacBook-Pro:simulator nicolas$ sbt
[info] Set current project to Simulator (in build file:/Users/nicolas/Private/simulator/)
> compile
[success] Total time: 1 s, completed 29-Oct-2016 14:30:04
> test
[info] MySpec:
[info] A pip
[info] - should pop
[info] Run completed in 312 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 31 s, completed 29-Oct-2016 14:30:37
如您所见,编译是即时的(1 秒),测试本身在 312 毫秒内运行。什么可以解释它实际上需要 31s 来运行它们?
一开始不是这样的,他们在几秒钟内运行然后突然跳到 30 秒(即使只有 1 个非常快的测试) 重新启动计算机后也会发生这种情况。
这是我的 build.sbt 以防万一:
lazy val root = (project in file(".")).
settings(
name := "Simulator",
version := "0.1",
scalaVersion := "2.11.8"
)
// scala JSON library
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.2"
// ScalaTest dependencies
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.0"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % "test"
// QuickLens
libraryDependencies += "com.softwaremill.quicklens" %% "quicklens" % "1.4.8"
谢谢!
编辑:我做了一个新项目(最小的),我有同样的问题,这是完整的树
project
| - build.sbt
| - src
| - main
| | - scala
| | - hw.scala
| - test
| - scala
| - myTest.scala
hw.scala:
object Hi { def main(args: Array[String]) = println("Hi!") }
myTest.scala:
import org.scalatest._
class MySpec extends FlatSpec with Matchers {
"A pip" should "pop" in { true should be(true) }
}
same build.sbt as above
最佳答案
如果您最近升级到 macOS Sierra,您可能会遇到这个问题:SBT test extremely slow on macOS Sierra
关于performance - Scalatest 需要 30 秒才能开始测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40319650/