junit provides new assert validation methods called assertThat (), which Matchers uses, and should provide more readable test code and better error messages.
To use this, junit has some basic connectors. You can start with them for basic tests.
If you want to use more helpers, you can write them yourself or use lib.bmp.
The following example shows how to use empty matches in an ArrayList:
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())); } }
(I included hamcrest-all.jar in my build path)
cpater Apr 6 2018-11-11T00: 00Z
source share