File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes How to write a class so that it can be mocked? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "How to write a class so that it can be mocked?" Watch "How to write a class so that it can be mocked?" New topic
Author

How to write a class so that it can be mocked?

roger wong
Greenhorn

Joined: Oct 21, 2009
Posts: 29
I am studying junit. Currently there are many ways(jmock, easymock, virtualmock, java proxy, and blah blah blah) to mock a class.

I just wonder how to write a class so that it can be mocked?

Thank you.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You don't need to do anything special, although some frameworks are happier mocking interfaces rather than classes.

The biggest thing to keep in mind is to have as few dependencies as possible in the class being mocked: reduce or eliminate static dependencies, inject as much functionality as possible/practical, and so on.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to write a class so that it can be mocked?
 
Similar Threads
Generics on JSP
Panel vs Frame
Writing xml data to file from TCP port
Testing custom annotations
Help with Java