Java/ JUnit - AssertTrue vs AssertFalse

后端 未结 7 815
旧巷少年郎
旧巷少年郎 2020-12-23 09:28

I\'m pretty new to Java and am following the Eclipse Total Beginner\'s Tutorials. They are all very helpful, but in Lesson 12, he uses assertTrue for one test c

相关标签:
7条回答
  • 2020-12-23 10:16

    The point is semantics. In assertTrue, you are asserting that the expression is true. If it is not, then it will display the message and the assertion will fail. In assertFalse, you are asserting that an expression evaluates to false. If it is not, then the message is displayed and the assertion fails.

    assertTrue (message, value == false) == assertFalse (message, value);
    

    These are functionally the same, but if you are expecting a value to be false then use assertFalse. If you are expecting a value to be true, then use assertTrue.

    0 讨论(0)
提交回复
热议问题