【问题标题】:ScalaTest DeferredAbortedSuite error when running simple tests.运行简单测试时出现 ScalaTest DeferredAbortedSuite 错误。
【发布时间】:2016-08-29 02:23:24
【问题描述】:

我的原始代码还有很多事情要做,这让我分心了问题的真正原因。 这抓住了根本问题。

import org.scalatest.AsyncFlatSpec
import scala.concurrent.Future

class AsyncFlatSpecSpec extends AsyncFlatSpec
{
  it should "parse an XML file" in {
    // ... Parsing ...
    Future.successful(succeed)
  }

  it should "parse an XML file" in {
    // ... Serializing ...
    Future.successful(succeed)
  }
}

这产生了这些错误:

[info] DeferredAbortedSuite:
[error] Uncaught exception when running AsyncFlatSpecSpec: java.lang.ArrayIndexOutOfBoundsException: 17
[trace] Stack trace suppressed: run last test:testOnly for the full output.

在我的代码中的任何地方都没有发生数组访问。怎么回事?

运行“last test:testOnly”并没有多大帮助:

[info] DeferredAbortedSuite:
[error] Uncaught exception when running AsyncFlatSpecSpec: java.lang.ArrayIndexOutOfBoundsException: 17
sbt.ForkMain$ForkError: java.lang.ArrayIndexOutOfBoundsException: 17
  at org.scalatest.exceptions.StackDepth$class.stackTraceElement(StackDepth.scala:63)
  at org.scalatest.exceptions.StackDepth$class.failedCodeFileName(StackDepth.scala:77)
  at org.scalatest.exceptions.StackDepthException.failedCodeFileName(StackDepthException.scala:36)
  at org.scalatest.exceptions.StackDepth$class.failedCodeFileNameAndLineNumberString(StackDepth.scala:59)
  at org.scalatest.exceptions.StackDepthException.failedCodeFileNameAndLineNumberString(StackDepthException.scala:36)
  at org.scalatest.tools.StringReporter$.withPossibleLineNumber(StringReporter.scala:442)
  at org.scalatest.tools.StringReporter$.stringsToPrintOnError(StringReporter.scala:916)
  at org.scalatest.tools.StringReporter$.fragmentsForEvent(StringReporter.scala:747)
  at org.scalatest.tools.Framework$SbtLogInfoReporter.apply(Framework.scala:622)
  at org.scalatest.tools.FilterReporter.apply(FilterReporter.scala:41)
  at org.scalatest.tools.SbtDispatchReporter$$anonfun$apply$1.apply(SbtDispatchReporter.scala:23)
  at org.scalatest.tools.SbtDispatchReporter$$anonfun$apply$1.apply(SbtDispatchReporter.scala:23)
  at scala.collection.Iterator$class.foreach(Iterator.scala:893)
  at scala.collection.AbstractIterator.foreach(Iterator.scala:1336)
  at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
  at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
  at org.scalatest.tools.SbtDispatchReporter.apply(SbtDispatchReporter.scala:23)
  at org.scalatest.tools.Framework$SbtReporter.apply(Framework.scala:1119)
  at org.scalatest.tools.Framework.org$scalatest$tools$Framework$$runSuite(Framework.scala:387)
  at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:506)
  at sbt.ForkMain$Run$2.call(ForkMain.java:296)
  at sbt.ForkMain$Run$2.call(ForkMain.java:286)
  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
  at java.lang.Thread.run(Thread.java:745)

困惑,我退回到非异步版本,看看是否有任何影响 更好。

import org.scalatest.FlatSpec
class FlatSpecSpec extends FlatSpec {

  it should "parse an XML file" in {
    // ... Parsing ...
    succeed
  }

  it should "parse an XML file" in {
    // ... Serializing ...
    succeed
  }

}

它产生了这个不同但仍然神秘的错误消息:

[info] DeferredAbortedSuite:
[info] Exception encountered when attempting to run a suite with class name: org.scalatest.DeferredAbortedSuite *** ABORTED *** (20 milliseconds)
[info]   Exception encountered when attempting to run a suite with class name: org.scalatest.DeferredAbortedSuite (AsyncFlatSpecSpec.scala:32)
[info] ScalaTest

为了完整起见,这里是我的 build.sbt 的相关部分:

scalaVersion := "2.11.8"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0-M15" % "test"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.0-M15"

这最终是我的一个小错误,但我想发布这个是为了让其他人在谷歌上搜索这些错误。

【问题讨论】:

    标签: scala unit-testing scalatest


    【解决方案1】:

    许多读者在浏览示例时可能会注意到,问题在于我复制/粘贴了相同的测试描述。 这允许代码编译,但会在运行时失败并出现错误 不要将描述确定为罪魁祸首。

    我的错误很愚蠢,但如果编译器以更有用的方式报告它会很好。

    【讨论】:

      猜你喜欢
      • 2017-07-21
      • 2013-01-01
      • 2015-07-17
      • 2021-03-30
      • 1970-01-01
      • 1970-01-01
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多