我有类似的东西
@Test(expected = IllegalArgumentException.class)
public void cdIntoNonExistantFolder() {
cdTool.changeDirectory("nonexistant");
assertThat(cdTool.getStatusCode(), not(equalTo(0)));
}
我相信
assertThat
不会运行,因为changeDirectory
会抛出异常。是否有可能使其继续运行? 最佳答案
您可以使用finally
:
@Test(expected = IllegalArgumentException.class)
public void cdIntoNonExistantFolder() {
try {
cdTool.changeDirectory("nonexistant");
}
finally {
assertThat(cdTool.getStatusCode(), not(equalTo(0)));
}
}