Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用hamcrest的Assert.fail等价物_Java_Unit Testing_Junit_Hamcrest - Fatal编程技术网

Java 使用hamcrest的Assert.fail等价物

Java 使用hamcrest的Assert.fail等价物,java,unit-testing,junit,hamcrest,Java,Unit Testing,Junit,Hamcrest,我将JUnit用于Assert.fail,但我不知道它的等价物是什么。有人知道吗?matcherasert类有以下方法: public static void assertThat(String reason, boolean assertion) { if (!assertion) { throw new AssertionError(reason); } } 因此,当调用时,它将是最接近的东西: MatcherAssert.assertThat("Fail

我将JUnit用于Assert.fail,但我不知道它的等价物是什么。有人知道吗?

matcherasert类有以下方法:

public static void assertThat(String reason, boolean assertion) {
    if (!assertion) {
        throw new AssertionError(reason);
    }
}
因此,当调用时,它将是最接近的东西:

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

根据测试的结构,我发现使用not(anything())匹配器更自然

@Test(expected = MyException.class)
public void runMyTestHere() {

    ...

    MyObj result = myService.getThing(id);
    assertThat("Exception should have been thrown.", result, is(not(anything())));
}