aspose file tools*
The moose likes Testing and the fly likes What is the best practice? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "What is the best practice?" Watch "What is the best practice?" New topic
Author

What is the best practice?

Marcin Mogiela
Greenhorn

Joined: Aug 30, 2007
Posts: 14
Lets assume we have the following:



Test cases:



What would be the best solution to test h() method?

* one solution that comes to my mind is:


* 2nd solution:


* 3rd:

[ March 20, 2008: Message edited by: Marcin Mogiela ]

SCJP 5.0, SCWCD 1.4
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30965
    
158

Marcin,
This is mainly a personal preference, but I like #1 the best. Ideally, I would see if I could make f() and g() private and test entirely through h().


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I agree with Jeanne, unless f() and g() are very complex and/or slow. (In general, these things are much easier to discuss on real examples.)


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30965
    
158

Originally posted by Ilja Preuss:
unless f() and g() are very complex and/or slow.

And I agree with Ilja

I assumed f() and g() were ok to unit test since the original post included a unit test for them.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the best practice?