Java/ JUnit - AssertTrue vs AssertFalse

后端 未结 7 819
旧巷少年郎
旧巷少年郎 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 09:51

    assertTrue will fail if the second parameter evaluates to false (in other words, it ensures that the value is true). assertFalse does the opposite.

    assertTrue("This will succeed.", true);
    assertTrue("This will fail!", false);
    
    assertFalse("This will succeed.", false);
    assertFalse("This will fail!", true);
    

    As with many other things, the best way to become familiar with these methods is to just experiment :-).

提交回复
热议问题