Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList in a tester class

 
Lisa Beglaw
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am building a tester class and one of my methods I need to test is...


I am not sure how I can build this in my tester class.
I took a shot in the dark and tried...

...but no luck.

Any suggestions?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What constitutes a test? A meaningful test has a pre-condition, some kind of action, and a post-condition. What are those in your situation?

Since you don't seem to be using the result returned by "movieCollection.neverBeenRented()", how/what would it be testing?
 
Lisa Beglaw
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess what I am testing is that when I test the method neverBeenRented() it creates the ArrayList and moves my two never been rented movies into it.

edited for spelling.
[ August 10, 2005: Message edited by: Lisa Beglaw ]
 
Lisa Beglaw
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just finished and have every other test method working in my test class except the Array.

I can see it doesn't follow the same pattern as the rest do with testing, but I am not sure what I am missing.
 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please post your code and let us know what exactly is missing?
 
Lisa Beglaw
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I twit I am...here it is...

And the method I am trying to test is
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I guess what I am testing is that when I test the method neverBeenRented() it creates the ArrayList and moves my two never been rented movies into it.


In that case, wouldn't



do the trick? Or are you using JUnit?
 
Lisa Beglaw
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If statements in a tester class? Have you opened up a whole new world to me?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Have you opened up a whole new world to me?


If so, then it was easy. Hope I can do it again some time

Maybe we don't have the same concept of a "tester class". My idea would have been that it's either a general class whose purpose is to test some other class (in which case it may do so by whatever means available), or maybe a JUnit test, in which case the above would be something like "assertEquals(2, movieCollection.neverBeenRented().size())". Are you working with another definition?
[ August 10, 2005: Message edited by: Ulf Dittmer ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic