0

我们的 scala 测试用例为 ex 调用了一个 REST API。创建一个用户并通过解析输出响应来检查 userId 是否实际创建。如果 REST API 抛出任何错误,则 userId 为空,并且org.scalatest.exceptions.TestFailedException: "" equaled ""由于断言条件 (assert(userId != "")) ,customReport 将事件显示为 TestFailed

有没有办法可以将 REST API 的响应传递给记者。请指教。

class CustomReport extends Reporter {


  override def apply(event: Event): Unit = {

}

}
4

1 回答 1

0

考虑通过线索提供有关失败的自定义信息,例如,

assert(userId != "", myCustomInformation)

或者

withClue(myCustomInformation) {
  userId should not be empty
}

customInformation比如说,可能在哪里

case class MyCustomInformation(name: String, id: Int)
val myCustomInformation = MyCustomInformation("picard", 42)

这是一个工作示例

import org.scalatest._

class ClueSpec extends FlatSpec with Matchers {
  case class MyCustomInformation(name: String, id: Int)

  "Tests failures" should "annotated with clues" in {
    withClue(MyCustomInformation("picard", 42)) {
      "" should not be empty
    }
  }
}

哪个输出

[info] Tests failures
[info] - should annotated with clues *** FAILED ***
[info]   MyCustomInformation(picard,42) "" was empty (HelloSpec.scala:10)

有关自定义报告器的示例,请考虑https://stackoverflow.com/a/56790804/5205022

于 2019-11-21T11:33:52.057 回答