• Post Reply Bookmark Topic Watch Topic
  • New Topic

Junit testing  RSS feed

 
rick pine
Ranch Hand
Posts: 90
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i get some guidance with Junit testing. I need to create a junit test for this class, but i cant quite figure things out. Been at it for a few hours and cant get one test right. well, except for the blank ones.

package gpsWithUnitTests;



here is what i have, and that test its coming out incorrect



 
rick pine
Ranch Hand
Posts: 90
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please ignore method on line 23 forgot to delete it. I dont like that approach because im comparing string literals.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37496
545
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rick,
I have two pieces of advice. First is that you don't need to have a test method for every method in the class. They can share. For example, you can test getLatitude and getLongitude in the same test. If you even need the setter. Often when a constructor takes parameters, the object is immutable and you don't need the setter.

The toString() method is a good one to test. You know what the expected value should be for a given longitude and latitude so your test can assert that is the case.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!