Reputation: 4787
I have a two string array in java where I am comparing the whole array using assertArrayEquals
.
example:
Expected:[CTSCAT, CTSSCH, PERSONS, ID, CTSCAT, CTSSCH, ORDERS, PERSONID, 1, 3, 3, FK_PERSONORDER, PK_PERSON, 7]
Actual:[CTSCAT, CTSSCH, PERSONS, ID, CTSCAT, CTSSCH, ORDERS, PERSONID, 1, 3, 3, FK_PERSONORDER, PK_PERSON, 7]
But know I want to compare some element of array instead of entire array. Like in same example I only want to check first two element.
Upvotes: 0
Views: 247
Reputation: 444
You can use Hamcrest matchers (javadoc):
assertThat(arr1, Matchers.arrayContaining(arr2));
Upvotes: 0
Reputation: 2709
Try using AssertJ library. It has very good support for arrays and its much more readable.
You can find the array example here
Upvotes: 0
Reputation: 2592
You can compare with the help of assertEquals:
assertEquals(arr1[0],arr2[0]);
and so on..
Upvotes: 1