gpt4 book ai didi

java - 最佳实践 : fail() vs assertTrue(false)

转载 作者:太空狗 更新时间:2023-10-29 23:00:24 25 4
gpt4 key购买 nike

当故意使测试用例失败时(例如,当未抛出异常时)我看到人们同时使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com