• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Junit testing

 
Ranch Hand
Posts: 90
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic