您可以使用Assume来完成此操作.
在下面显示的示例中,我想检查状态,如果precondition == true并且我想断言在precondition == false的情况下抛出异常.
@Test
public final void testExecute() throws InvalidSyntaxException {
Assume.assumeTrue(precondition); // Further execution will be skipped if this holds true
CommandResult result = sentence.getCommand().execute();
boolean status = Boolean.parseBoolean(result.getResult());
Assert.assertTrue(status);
}
@Test(expected = InvalidSyntaxException.class)
public final void testInvalidParse() throws InvalidSyntaxException {
Assume.assumeTrue(!precondition);
CommandResult result = sentence.getCommand().execute();
}
希望这对你有所帮助.