英文:
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")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论