我正在尝试使用 specs2 比较两个非常大的数组。不幸的是,当数组不相等时,它会显示每个数组的实际内容和预期内容。无论如何,我是否可以减少实际和预期显示的数据量,或者仅针对此特定测试完全删除它。
我尝试过使用 setMessage 但这不会影响实际和预期部分。
bytes1 must be_== (bytes2).setMessage("A does not mach B")
我实际上想做的是比较两个输入流。我也有兴趣听听是否有人对如何做到这一点有更好的想法,而不是将它们转换为数组。
最佳答案
您可以通过实现自己的 Diffs
来控制差异的处理方式特质:
import org.specs2._
import main._
class MyDiffs extends Diffs {
/** @return true if the differences must be shown */
def show: Boolean = true
/** @return true if the differences must be shown for 2 different strings */
def show(expected: String, actual: String): Boolean =
expected.size + actual.size < 100
/** @return the diffs */
def showDiffs(expected: String, actual: String): (String, String) =
(expected.take(10).mkString, actual.take(10).mkString)
/** @return true if the full strings must also be shown */
def showFull: Boolean = false
/** this method is not used and will be removed from the trait in a next release */
def separators: String = ""
}
class s extends Specification { def is =
args.report(diffs = new MyDiffs)^
"test" ! {
"abcdefghijklmnopqrstu" must_== "abcdefghijklmnopqrstuvwxyz"
}
}
x test
'abcdefghijklmnopqrstu' is not equal to 'abcdefghijklmnopqrstuvwxyz' (<console>:47)
Expected: qrstuvwxyz
Actual: lmnopqrstu
关于unit-testing - 如何减少specs2中的故障显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14845109/