• 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

how to test the setter methods

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've gotten the class done, and the driver is getting close. Any pointers in the right direction would help. I don't want you to do it for me, but perhaps a hint or two?

Here is the class with the setter methods(I needed to make it mutable):



and here is the test driver as it sits:

 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your test, examine the attribute before calling the setter. Then call the setter with a new value. Examine the attribute again and compare the value to what you saw before.
 
Cali Kim
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dennis Deems wrote:In your test, examine the attribute before calling the setter. Then call the setter with a new value. Examine the attribute again and compare the value to what you saw before.



This is French to me. I understand creating a new value, but I'm having a problem deciding what values to use. The initial values (day, month, year) are all locked as private and will not transfer over into a test driver. Should I create new ones within the test driver? If so, how then will I be sure that it is calling the setter methods for testing?
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cali Kim wrote:I understand creating a new value, but I'm having a problem deciding what values to use. The initial values (day, month, year) are all locked as private and will not transfer over into a test driver. Should I create new ones within the test driver? If so, how then will I be sure that it is calling the setter methods for testing?



That's all Greek to me. Like Dennis said, if you want to test a setter method, then here's what you do:

(1) Get the value of the variable which the setter affects. Store it in a local variable. (If that counts as "creating a new one", then yes, create a new one.) If you're concerned that the variable in question is private, then use some public method of getting that value.

(2) Call the setter method to assign a different value than what you just got. (Why would you not be sure that the test driver would be calling the setter method?)

(3) Get the value of the variable again. Check that it is the value that the setter method assigned in step 2 and not the value originally acquired in step 1.
 
Cali Kim
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Cali Kim wrote:I understand creating a new value, but I'm having a problem deciding what values to use. The initial values (day, month, year) are all locked as private and will not transfer over into a test driver. Should I create new ones within the test driver? If so, how then will I be sure that it is calling the setter methods for testing?



That's all Greek to me. Like Dennis said, if you want to test a setter method, then here's what you do:

(1) Get the value of the variable which the setter affects. Store it in a local variable. (If that counts as "creating a new one", then yes, create a new one.) If you're concerned that the variable in question is private, then use some public method of getting that value.

(2) Call the setter method to assign a different value than what you just got. (Why would you not be sure that the test driver would be calling the setter method?)

(3) Get the value of the variable again. Check that it is the value that the setter method assigned in step 2 and not the value originally acquired in step 1.



Thank you...the way you put it made it a bit easier to understand. I've had a bit of a rough week so my head just isn't functioning as it normally would.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic