This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I just started using Junit and Netbeans IDE after using the command line compiler last year. I'm trying to get my code to pass the junit tests. I would rather use if() and .equals rather than assertEquals(). The above code is just one of many examples I have but if I can get the hang of this one I think I can do knock the rest out. It's telling me "double cannot be dereferenced". Been stuck on this the few days so finally throwing in the towel and reaching out for help.
I'm assuming getExtendedPrice() is returning a double, right? double is a primitive value, so it doesn't have an equals() method. You can use:
However, I'd really suggest getting used to using the assert methods. Why don't you like them? They give you much richer feedback in general - e.g. the framework can tell you "the expected value was 100.0, but the actual value was 99.9" (or something like that). Yes, you could do that yourself, but it's more work.
I also think assertion methods make the test more obvious and readable, which is really important.
Joined: Apr 26, 2012
Yes the getExtendedPrice() returns a double. Thanks much works just fine now, makes sense also. I just reread the testing rules and he wants us to use if() rather than what pops up automatically, in class the teacher used .equals() but I went over the class video again and assertEquals() is ok as long as we use in in and if() with the fail() within the if.