Scalatest需要30秒才能开始测试

时间:2016-10-29 13:39:22

标签: performance scala testing sbt scalatest

编辑:我找到了解决方案。杀死终端似乎解决了这个问题。我想它在计算机重启时没有终止。 但我仍然不知道问题出在哪里。

我注意到,为了开始测试,神圣的剑突然变得更慢。 我删除了所有测试,只剩下一个,只测试真实。 这是我得到的(使用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

正如您所看到的,编译是即时的(1s),测试它们在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

1 个答案:

答案 0 :(得分:0)

如果您最近升级到macOS Sierra,则可能会遇到此问题:SBT test extremely slow on macOS Sierra