JUnit Access DataSource from Context?

G

gilgantic

I am trying to run JUnit test case in my WebSphere Studio, but it fails
during a context.lookup in my DAO class. The DataSource is defined on
the server, so I start the Development Test Server. Here is a snippet
of the the code in my DAO class.

Context context = new InitialContext();
DataSource dataSource = (DataSource) context.lookup("jdbc/sample");

Is it because my Dev Test Server and JUnit are using two different
JVMs? How do I solve this problem?
 
R

Ray McVay

gilgantic said:
I am trying to run JUnit test case in my WebSphere Studio, but it fails
during a context.lookup in my DAO class. The DataSource is defined on
the server, so I start the Development Test Server. Here is a snippet
of the the code in my DAO class.

Context context = new InitialContext();
DataSource dataSource = (DataSource) context.lookup("jdbc/sample");

Is it because my Dev Test Server and JUnit are using two different
JVMs?
I think so although I've never understood why since JNDI is supposed to
be a network service.
How do I solve this problem?
I've been told, "use Cactus." You can also include the test classes in
the web app and drive them from JSPs with the app running in a test
environment.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top