当故意使测试用例失败时(例如,当未抛出异常时)我看到人们同时使用 fail() 和 assertTrue(false)。使用其中一种有什么优势吗?
try {
//method call that should throw exception
fail("oops");
} catch (Exception e) {}
对比
try {
//method call that should throw exception
assertTrue("oops", false);
} catch (Exception e) {}
最佳答案
Are there any advantages to using one or the other?
功能上,没有。但是,fail()
传达的意图更清楚,因此更好。
关于java - 最佳实践 : fail() vs assertTrue(false),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12939362/