• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Testing void method in Junit

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.

 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tom Mordon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I guess everyone has an angle. Fine, what do you want? Just know that you cannot have this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic