views:

78

answers:

2

I am using an external library in a java project but I am not sure how can I integration test it with my code. For example: Let us say I am using a string encryption library to encrypt passwords.

Please enlighten.

Thanks

+2  A: 

You are probably thinking of integration testing, not unit testing. Generally I don't unit test code that isn't my own. What I would do for integration testing is basically write tests similar to my unit tests for my code, but not mock out the external library -- i.e., use it directly. You may need to do some set up to create a test environment, including any data you want to use in the test, in which to carry this out. The integration tests may be less extensive than your unit tests since you really only need to test the paths that exercise the external functionality, not necessarily all paths through your code.

tvanfosson
Thanks for that. What are your thoughts on using a bridge pattern in this situation?
andHapp
If you just want to make sure that the appropriate library calls are being made, use mocking with expectations. If you can't mock the external library, create a wrapper around the library that can be mocked and mock that. Check out the JMock framework if you aren't familiar with mocking.
tvanfosson
A: 

I was looking through Stack overflow and I might have to use a bridge pattern for this. Not entirely sure but then again I have only spent a little time on this probably needs more investigation.

andHapp
can you please elaborate further what you are trying to test? My favourite test API was EasyMock, very partial to it. If all you want to check is that the external library is being called by your code, then all this is fairly easy in most test APIs.
j pimmel