即使 Junit 测试从中抛出断言错误,“最终”块也会触发吗?
2022-09-02 21:17:24
块中的方法是否会在 Junit 断言错误上运行?writer.close()
finally { }
假定以下代码:
@Test
public void testWriter() {
try {
writer.open();
final List<MyBean> myBeans = new ArrayList<ProfileBean>();
/** Add 2 beans to the myBeans List here. **/
final int beansWritten = writer.writeBeans(myBeans);
// Say this assertion error below is triggered
org.junit.Assert.assertEquals("Wrong number of beans written.", -1, profilesWritten);
} finally {
writer.close(); // will this block run?
}
}
现在,块会像常规流一样运行吗?finally()