aspose file tools*
The moose likes Testing and the fly likes Testing classes that have dependency on third party classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Testing classes that have dependency on third party classes" Watch "Testing classes that have dependency on third party classes" New topic
Author

Testing classes that have dependency on third party classes

Kiran Jakkula
Greenhorn

Joined: Aug 04, 2010
Posts: 7
Hi,

The other day i was trying to write JUnit test case for a class, but the class has dependency on a third party class ( included through a jar file). I was looking at jMock. But i wasn't sure how to mock a class whose source code i don't have. How are such classes tested?
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

its simple,you can directly mock it..
import a third party class file in your class.
and say mock.
but make sure your follow the rules for mocking.

Like for mockito.

you cannt mock the final classes


SCJP6.0,My blog Ranchers from Delhi
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30555
    
152

Kiran,
You have the method names and parameters even if you don't have the source. That's all you need to mock it out.

If the class isn't mockable (like being final), you can write a wrapper for it.


[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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Testing classes that have dependency on third party classes