Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Testing classes that have dependency on third party classes

 
Kiran Jakkula
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34371
345
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic