我原来的代码还有很多,这让我分心了问题的真正原因。 这抓住了基本问题。
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.
我的代码中的任何地方都没有发生数组访问。发生了什么事?
跑步"最后一次测试: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)
感到困惑,我退回到非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
}
}
它产生了这个不同但仍然含糊不清的错误信息:
[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"
这对我来说最终是一个微不足道的错误,但我想发布这个是为了其他人搜索这些错误。
答案 0 :(得分:36)
许多读者在浏览示例时可能会注意到,问题是我复制/粘贴了相同的测试说明。 这允许代码编译,但在运行时会因错误而失败 不要将描述确定为罪魁祸首。
我的愚蠢错误,但如果编译器以更有用的方式报告它会很好。