简体   繁体   English

Nunit断言-Assert.False(true)vs Assert.True(false)

[英]Nunit Assertions - Assert.False(true) vs Assert.True(false)

New to unit testing, and am a little confused on what the difference between Assert.False(true) vs Assert.True(false) would be? 单元测试的Assert.False(true)Assert.True(false) Assert.False(true)Assert.True(false)之间的区别会有些困惑吗?

Could someone explain how these are different? 有人可以解释这些有何不同吗?

Both are guaranteed to fail. 两者都保证会失败。

Assert.False passes if the argument evaluates to false , which true does not. 如果参数评估为falseAssert.False通过Assert.False ,否则为true

Assert.True passes if the argument evaluates to true , which false does not. 如果参数评估为true ,则Assert.True通过,而false则不然。

The difference is what condition makes them pass, but when passing a constant as your code does; 区别在于是什么条件使它们通过,但如代码那样传递常量时; it just means a guaranteed failure. 这只是意味着有保证的失败。 They also have different semantic meaning (for obvious reasons). 它们也具有不同的语义(出于明显的原因)。

Both Assert.True(false) and Assert.False(true) will cause the test to fail. Assert.True(false)Assert.False(true)都将导致测试失败。 They both can be read like "Make sure this value is true, if it's not then fail." 两者都可以读为“确保此值正确,如果没有,那么就失败了”。 and "Make sure this value is false, if it's not then fail." 和“确保此值是假的,如果不是,则失败。” respectively. 分别。 So whatever the condition/value in your assertion is, it must evaluate to the respective value or the test will fail. 因此,无论您的断言中的条件/值是什么,它都必须评估为相应的值,否则测试将失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM