By
using ‘arrayWithSize’ method, you can create a matcher for arrays that matches
when the length of the array equals the specified size.
Ex
String
arr[] = { "Hello", "How", "are",
"you"};
assertThat("arr
size should be equal to 4", arr, arrayWithSize(4));
Find
the below working application.
TestApp.java
package com.sample.tests; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.arrayWithSize; import org.junit.Test; public class TestApp { @Test public void testmethod() { String arr[] = { "Hello", "How", "are", "you"}; assertThat("arr size should be equal to 4", arr, arrayWithSize(4)); } }
No comments:
Post a Comment