简体   繁体   English

运行简单测试时ScalaTest DeferredAbortedSuite错误。

[英]ScalaTest DeferredAbortedSuite error when running simple tests.

My original code had a lot more going on, which distracted me from the true cause of the problem. 我的原始代码还有很多,这让我分心了问题的真正原因。 This captures the essential problem. 这抓住了基本问题。

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)
  }
}

This produced these errors: 这产生了以下错误:

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

There is no array access happening anywhere in my code. 我的代码中没有任何数组访问发生。 What's going on? 这是怎么回事?

Running "last test:testOnly" wasn't much help: 运行“最后一次测试: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)

Confused, I retreated to the non-Async version, to see if that fared any better. 困惑,我退回到非Async版本,看看是否更好。

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
  }

}

It produced this different, but still cryptic error message: 它产生了这个不同但仍然含糊不清的错误信息:

[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

For completeness, here are the related portions of my build.sbt: 为了完整性,这是我的build.sbt的相关部分:

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

This was ultimately a trivial mistake on my part, but I wanted to post this for the sake of anyone else Googling these errors. 这对我来说最终是一个微不足道的错误,但我想发布这个是为了其他任何人用Google搜索这些错误。

As many readers probably noticed while going through the examples, the problem was that I had copy/pasted the same test description. 正如许多读者在阅读示例时可能注意到的那样,问题在于我复制/粘贴了相同的测试描述。 This allows the code to compile, but will fail at runtime with errors that don't identify the description as the culprit. 这允许代码编译,但在运行时会因错误而导致错误,而这些错误并未将描述标识为罪魁祸首。

Stupid error on my part, but it would be nice if the compiler reported it in a more helpful way. 我的愚蠢错误,但如果编译器以更有用的方式报告它会很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM