简体   繁体   中英

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.

(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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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