Skip to content

(计算机)Assert

Chen Xiaojie edited this page Dec 18, 2022 · 1 revision

英语词典是这样解释 Assert 的:[^1]

to say that something is certainly true 斷言;肯定地說

ex: *He asserts that she stole money from him.*他一口咬定她偷了他的錢。

软件工程

在Java中,我们常常使用 Assert 一词作为判断测试成功与否。

import static org.junit.Assert.*;

assertEquals(期待值,真实值);

上述代码可以翻译为: 「assert that 期待值 equals 真实值」,虽然这里也可以翻译成「断言这里的期待值与真实值相等」,但是从更真实的语境出发,不应该是断言,而应该是检查 (check) ,检查代码是否运行正常,不正常则报错。

参考 References

[^1]: assert 在英语-中文(繁体)词典中的翻译 - Cambridge Dictionary

Clone this wiki locally