Want to use JUnit and Hamcrest together? junit provides new check assert methods named assertThat() which uses Matchers and should provide a more readable testcode and better failure messages.
To use this there are some core matchers included in junit. You can start with these for basic tests.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | package com.test; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import java.util.ArrayList; import java.util.List; import org.junit.Test; public class EmptyTest { @Test public void testIsEmpty() { List myList = new ArrayList(); assertThat(myList, is(empty())); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.