aspose file tools*
The moose likes Testing and the fly likes still new to testing, how do I test this method: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "still new to testing, how do I test this method:" Watch "still new to testing, how do I test this method:" New topic
Author

still new to testing, how do I test this method:

Dan Maples
Ranch Hand

Joined: Jun 21, 2004
Posts: 153
hey guys, I have a method that looks like this:


I am trying to figure out the best way to run a test for it, any ideas? I am considering haveing a text file that I read with some strings and doubles in the text, would that be a good way to do it? Any other ways?
Thanks in advance, Dan


-Dan
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
What's wrong with

?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Lasse Koskela:
What's wrong with

?

That is, except that one of the assertions fails
Dan Maples
Ranch Hand

Joined: Jun 21, 2004
Posts: 153
Lasse, nothing is wrong with that, I was just wondering if there was anything special about testing strings and doubles. Also if I could get a loop in there it would be helpfull too Well I guess there is nothing special about this case then.

I also ran accross another problem I'm sure you can help me with. I can't get assertEquals() to work with doubles that are variable i.e.

how can I get that to work?
Thanks for your help!
[ July 02, 2004: Message edited by: dan maples ]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Also if I could get a loop in there it would be helpfull too

Sure you can. Using the suite() method:


I can't get assertEquals() to work with doubles that are variable i.e.
how can I get that to work?

There is no assertEquals(double expected, double actual) but there is an assertEquals(double expected, double actual, double delta). See my earlier example of how you typically use it.
[ July 02, 2004: Message edited by: Lasse Koskela ]
Dan Maples
Ranch Hand

Joined: Jun 21, 2004
Posts: 153
Thanks so much, you've been more than helpfull, but just one last thing I'm a little unsure about is:
assertEquals(double expected, double actual, double delta).

what is delta?
Thanks again-Dan
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
"delta" is the acceptable deviation of the actual result from the expected result (double and float are approximations!). Typically the value for delta is something like 0.0000001d or 0.0000000001d or some other very small number...
Dan Maples
Ranch Hand

Joined: Jun 21, 2004
Posts: 153
thank you so much, you've been so helpful, I really appreciate it.
-Dan
 
jQuery in Action, 2nd edition
 
subject: still new to testing, how do I test this method: