scala - 有什么方法可以在最新的 SBT 版本中抑制来自 ScalaTest 的堆栈跟踪?

标签 scala sbt scalatest

当 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/

相关文章:

java - 你如何找到两个本地时间之间的秒数?

scala - Scalikejdbc 查询结果作为流

scala - src_managed 中的源文件不是 SBT 中项目源的一部分

java - sbt Scalatest NoClassDefFoundError

scala - 如何从 ScalaTest 获取指示测试套件失败的返回值?

ScalaTest afterAll() 在每次测试后被调用

scala - 使用喷雾客户端进行多个请求时的 akka 超时

scala - 无法在intellij IDE的Scala中找到或加载主类

sbt - SBT 项目定义文件的弃用和功能警告

scala - 设置 SBT 的堆栈大小