简体   繁体   English

Assert.assertAllValuesInArrayAreEqual-使用junit在java中进行单元测试,没有这样的方法吗?

[英]Assert.assertAllValuesInArrayAreEqual - unit testing in java using junit, there is no such method?

Or is there ? 还是在那里?

I just have 我只有

int[] results

and want to check each element in array has the same int value. 并要检查数组中的每个元素具有相同的int值。

(yeah I could just loop through them). (是的,我可以遍历它们)。

There's no need to loop, just convert the array into a Set object and then check its length, if the length is 1 then everything in the array was equal. 无需循环,只需将数组转换为Set对象,然后检查其长度,如果长度为1,则数组中的所有内容均相等。

    Integer[] myArray = ...;
    assertThat(new HashSet(Arrays.asList(myArray)).size(), is(1));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM