当 SBT 中的 ScalaTest 测试失败时,我会得到堆栈跟踪。我试过set traceLevel in Test := -1
在 SBT 提示符下,尝试更改 build.sbt
中的内容文件等,但似乎没有任何帮助。
我想摆脱的是:
> test
[info] TestWritingFunctions:
[info] - threeSquares examples *** FAILED ***
[info] scala.NotImplementedError: an implementation is missing
[info] at scala.Predef$.$qmark$qmark$qmark(Predef.scala:252)
[info] at TestWritingFunctions$$anonfun$1.apply$mcV$sp(WritingFunctions.scala:17)
[info] at TestWritingFunctions$$anonfun$1.apply(WritingFunctions.scala:16)
[info] at TestWritingFunctions$$anonfun$1.apply(WritingFunctions.scala:16)
[info] at org.scalatest.Transformer$$anonfun$apply$1.apply(Transformer.scala:22)
[info] at org.scalatest.Transformer$$anonfun$apply$1.apply(Transformer.scala:22)
[info] at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
[info] at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
[info] at org.scalatest.Transformer.apply(Transformer.scala:22)
[info] at org.scalatest.Transformer.apply(Transformer.scala:20)
[info] ...
如您所见,测试失败是因为我使用了新的
???
构造为占位符,但由于我知道那里有一个占位符,所以我想要一个 *** FAILED ***
没有所有繁琐的消息。那可能吗?
最佳答案
您可以使用不带 F 或 S 的“-o...”(即,“-o”或“-oD”不会给您任何堆栈跟踪,但“-oF”、“-oS”或“-oDS”则不会会给你一个堆栈跟踪)。这意味着您将抑制所有堆栈跟踪。如果你根本没有指定记者,你会得到一个“-o”,这意味着没有堆栈跟踪。
如果您通常喜欢较短的堆栈跟踪,但不想在 ??? 引发 NotImplementedError 时看到它们,您可以覆盖 withFixture 并将 NotImplementedError 更改为挂起的测试:
import org.scalatest._
trait PendingIfUnimplemented extends SuiteMixin { this: Suite =>
abstract override def withFixture(test: NoArgTest): Outcome = {
super.withFixture(test) match {
case Failed(ex: NotImplementedError) => Pending
case other => other
}
}
}
这样,无论您选择什么,对于常规故障,您仍然会得到短的、长的或没有堆栈跟踪,但请参阅(待定)以了解因???而失败的测试。
关于scala - 有什么方法可以在最新的 SBT 版本中抑制来自 ScalaTest 的堆栈跟踪?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19383779/