我必须测试一个无循环图并且总是检查字符串是否不同不是很有用(它会引发异常)。必须有一个更好的解决方案,但我无法想出它,我有点迷失在 specs2 文档中。这是代码示例:
"BiDirectionalEdge" should {
"throw an Error for the wrong DirectedEdges" in prop {
(a :String, b :String, c :String, d :String) =>
val edge1 = createDirectedEdge(a, b, c)
val edge2 = createDirectedEdge(c, b, d)
new BiDirectionalEdge(edge1, edge2) must throwA[InvalidFormatException] or(a mustEqual d)
}
如果 a 和 c 相同,createDirectedEdge 将抛出异常(我对该行为有不同的测试)。