File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes JUnit EJB problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JUnit EJB problem" Watch "JUnit EJB problem" New topic

JUnit EJB problem

kota reddy malli

Joined: Sep 08, 2004
Posts: 2
I am getting the follwing exception when i use Junit on ejb... Can anybody help on this....

protected void setUp() throws Exception {
InitialContext initial = new InitialContext();

SampleEJBHome remoteHome = (SampleEJBHome)PortableRemoteObject.narrow(initial.lookup("java:comp/env/ejb/test/testSample/ejb/SampleEJBHome"),SampleTestCase.class);

sampleLocal = remoteHome.create();

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(
at javax.naming.InitialContext.getDefaultInitCtx(
at javax.naming.InitialContext.getURLOrDefaultInitCtx(
at javax.naming.InitialContext.lookup(
at test.testcase.SampleTestCase.setUp(
at junit.framework.TestCase.runBare(
at junit.framework.TestResult$1.protect(
at junit.framework.TestResult.runProtected(
at junit.framework.TestSuite.runTest(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Just checking, are you running these tests inside an EJB Container or directly within Eclipse?

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link:
subject: JUnit EJB problem
Similar Threads
Junit and Ejb - com/ibm/ejs/jts/jts/Current
WSAD 5.0 EJB Client jndi lookup problem
Jboss rar JNDI lookup
NoClassDefFoundError exception in InitialContext()
EJB Testing using JUnit