Erik Price wrote:
Hi,

I would like to write some unit tests for some classes. Unfortunately the classes use some JNDI data so they need to be run from within my app server (Tomcat in this case) in order to get the JNDI data from the web.xml. Any suggestions on a good way to go about this?

The solution is to use mock objects, though it will require a small refactoring made to the original code:


If I move the code that calls JNDI to its own method (called "getJndiData" or something), then I can write an anonymous subclass of my class in the unit test and override this method to return a predetermined (non-JNDI) mock value to use in the unit test. This obviously doesn't do anything to assure that the JNDI call works, but it means I can write my unit test now instead of waiting until my webapp is at a point where it is assembled "enough" to deploy and test in the container.

Someone else recommended Cactus, it is on my to-do list to learn how to use it but for right now I can use JUnit + the mock object.

Just thought I'd share this cool method.


Erik



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to