Search code examples
javaunit-testingjunithamcrest

Assert.fail equivalent using hamcrest


I use JUnit for Assert.fail but I do not know what is the Hamcrest equivalent. Does anyone know?


Solution

  • The MatcherAssert class has this method:

    public static void assertThat(String reason, boolean assertion) {
        if (!assertion) {
            throw new AssertionError(reason);
        }
    }
    

    So when invoked it would be the closest thing:

    MatcherAssert.assertThat("Fail here", false);