调试运行测试时的 SCollection 内容

huangapple go评论83阅读模式
英文:

Debugging SCollection contents when running tests

问题

有没有办法在运行单元测试(PipelineSpec)时查看 SCollection 的内容?

在许多机器上生产环境运行时,没有办法在一台机器上查看整个集合的内容,但我想知道是否有办法查看 SCollection 的内容(例如,在 IntelliJ 的调试模式下运行单元测试时)。

英文:

Is there any way to view the contents of an SCollection when running a unit test (PipelineSpec)?

When running something in production on many machines there would be no way to see the entire collection in one machine, but I wonder is there a way to view the contents of an SCollection (for example when running a unit test in debug mode in intellij).

答案1

得分: 1

如果您想将调试语句打印到控制台,可以使用debug方法,该方法是SCollections的一部分。下面是示例代码:

val stdOutMock = new MockedPrintStream
Console.withOut(stdOutMock) {
  runWithContext { sc =>
    val r = sc.parallelize(1 to 3).debug(prefix = "==")
    r should containInAnyOrder(Seq(1, 2, 3))
  }
}
stdOutMock.message.filterNot(_ == "\n") should contain theSameElementsAs
  Seq("==1", "==2", "==3")
英文:

If you want to print debug statements to the console then you can use the debug method which is part of SCollections. A sample code shown below

    val stdOutMock = new MockedPrintStream
    Console.withOut(stdOutMock) {
      runWithContext { sc =>
        val r = sc.parallelize(1 to 3).debug(prefix = "===")
        r should containInAnyOrder(Seq(1, 2, 3))
      }
    }
    stdOutMock.message.filterNot(_ == "\n") should contain theSameElementsAs
      Seq("===1", "===2", "===3")

huangapple
  • 本文由 发表于 2020年1月6日 14:41:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/59607728.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定