I am using mockrunner,i am new at this.my problem started when i began testing a web dynamic project which includes(structs,ejbs,servlet). i have a servlet called SetupServlet , which calls a class called Dispenser. In Dispenser we load all the EJB Refrences.
I started testing SetupServlet. I created a junittest case called TestservletTest as:
in the setUp() method i given this
i belive since i am extending my testclass as BasicServletTestCaseAdapter and ctx is for loading ejbs is for loading ejbs.is the problem.please give me solution on how to overcome this problem while testing setupservlet.
"i belive since i am extending my testclass as BasicServletTestCaseAdapter and ctx is for loading ejbs is for loading ejbs.is the problem"
Understanding the problem is half of the solution. You're right.
InitialContext class is considered an entry point to a naming system. In order to access application server's JNDI, an object of that class has to be created (as your code does). While your code is trying to create that object, it encounters "NamingContextFactory" class. It'll be available to an application if one of the following is correct:
Application runs in a container.
Application server provides a Java RMI client (typically a jar file) that can be added to the application's class path.
If you are writing unit tests, then application server is considered an external dependency. That is, you have to use Mocking techniques.
If you are writing integration tests that involve an actual application server, then either your test code has to run in an application container or you ought to have the Java RMI client in your class path. I prefer the later.