import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; @Test public void testFail() { String actualValue = "Hello"; String expectedValue = "World"; if (!actualValue.equals(expectedValue)) { fail("Test failed: expected " + expectedValue + ", but got " + actualValue); } }
import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; @Test public void testFailWithoutMessage() { String actualValue = "Hello"; String expectedValue = "World"; assertThat(actualValue, is(equalTo(expectedValue))); fail(); }In this example, we are using the assertThat method to compare actualValue with expectedValue. If the assertion fails, we are using the fail method without any message, it will fail and stop the execution of the test with just a generic message. The org.hamcrest.Matchers is a part of the Hamcrest package library.