Martin Dale Lyness
Martin Dale Lyness

Reputation: 590

Generating stub classes of 3rd party libraries for Unit Tests

I'm trying to do unit testing on an extension of the SWT library. I'm having trouble figuring out how to effectively mock and stub out the classes I'm extending to design my widgets.

The best solution I have thought of so far is to redefine the SWT classes in my test source so they get loaded over the top of the actual SWT libraries. Then I have the ability to make the stub methods do whatever I need.

The only problem i have with this method right now is the class files like Control.java are over 8K lines long and I want to stub each method, so I have no efficient way of removing the code that tries to access the underlying OS's GUI APIs I don't want to go through these lines of code.

There certainly must be something i'm doing horribly wrong, please help!

Upvotes: 0

Views: 522

Answers (1)

IAdapter
IAdapter

Reputation: 64737

Do you use any mocking framework?

I would advice you to try partial mocking with easymock (you just replace single method or methods in an object). There is also PowerMock for testing static/final methods and JMockit for some really hardcore testing.

I hope I answered your question.

Upvotes: 1

Related Questions