Hello all,
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 case and assertFalse
for another. Here's the code:
// Check the book out to p1 (Thomas)
// Check to see that the book was successfully checked out to p1 (Thomas)
assertTrue("Book did not check out correctly", ml.checkOut(b1, p1)); // If checkOut fails, display message
assertEquals("Thomas", b1.getPerson().getName());
assertFalse("Book was already checked out", ml.checkOut(b1,p2)); // If checkOut fails, display message
assertEquals("Book was already checked out", m1.checkOut(b1,p2));
I have searched for good documentation on these methods, but haven't found anything. If my understanding is correct, assertTrue
as well as assertFalse
display the string when the second parameter evaluates to false. If so, what is the point of having both of them?
Thanks for any help!
Thomas
Edit: I think I see what was confusing me. The author may have put both of them in just to show their functionality (it IS a tutorial after all). And he set up one which would fail, so that the message would print out and tell me WHY it failed. Starting to make more sense...I think that's the explanation, but I'm not sure. Talking it out to myself like this helps, so don't mind me lol.