我需要执行声明,指出集合包含来自其他集合的所有元素。在Spock中声明'containsAll'时显示更好的差异
下面的测试失败了,因为第一次收集不从第二个包含7
:
def first = [6, 1, 5, 2, 4, 3]
def second = [3, 4, 2, 5, 7, 6]
expect:
first.containsAll(second)
然而,测试失败是无法读取的。目前尚不清楚,只是7
丢失:
left.containsAll(right)
| | |
| false [3, 4, 2, 5, 7, 6]
[6, 1, 5, 2, 4, 3]
与AssertJ交易好得多:
java.lang.AssertionError:
Expecting:
<[6, 1, 5, 2, 4, 3]>
to contain:
<[3, 4, 2, 5, 7, 6]>
but could not find:
<[7]>
什么样的断言将是斯波克惯用得到更好失败消息containsAll
?
我认为斯波克有更好的支持比较字符串,所以你可以尝试'first.toString()== second.toString() '。当然这是一个肮脏的黑客... – injecteer