performance - Scalatest 需要 30 秒才能开始测试

标签 performance scala testing sbt scalatest

编辑:我找到了解决方案。杀死终端似乎可以解决问题。我猜它不会在计算机重新启动时终止。 但是我仍然不知道问题出在哪里。

我注意到 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/

相关文章:

c - 为什么我的更复杂的 C 循环更快?

scala - 为什么Scala不能绑定(bind)通配符类型参数?

unit-testing - Scala 中提供更多信息的断言

java - 使用链表和数组构建邻接表图的性能差异巨大

javascript - Node.js - 检查字符串是否表示大量元素的有效日期时间的最快方法是什么?

javascript - 如何使用 Cypress 和 Vue 中的组件进行组件测试?

testing - Clojure 测试 : global fixtures

javascript - 您最喜欢测试 JavaScript 代码片段的方法是什么?

WPF 位图性能

scala - 执行条件转换的惯用方法