Need some help in JUnit DB Connection testing
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Chaitanya_Puchakayala
Posted On:   Friday, September 24, 2010 04:31 AM

Hi, I am new to JUnit testing can any one help me in writing JUnit test case for DB connection testing Here is my sample code.. public class DBConnection { DataSource ds=null; Connection con=null; public Connection getDBConnection() throws Exception { try{ InitialContext cxt = new InitialContext(); if ( cxt == null ) { throw new Exception("Uh oh -- no context!"); } ds = (DataSource) cxt.lookup( "java:/comp/env/jdbc/postgres" ); con = ds.getConnection(); if ( ds == null ) { throw new Exception("Data source not found!"); } } catch (Exception e) { e.printSta   More>>

Hi,
I am new to JUnit testing can any one help me in writing JUnit test case for DB connection testing

Here is my sample code..
public class DBConnection
{
DataSource ds=null;
Connection con=null;

public Connection getDBConnection() throws Exception
{
try{
InitialContext cxt = new InitialContext();
if ( cxt == null ) {
throw new Exception("Uh oh -- no context!");
}

ds = (DataSource) cxt.lookup( "java:/comp/env/jdbc/postgres" );
con = ds.getConnection();
if ( ds == null ) {
throw new Exception("Data source not found!");
}
}
catch (Exception e) {
e.printStackTrace();
System.out.println("exceptio");
}
return con;
}

I want to write test case for the above DB connection how to write testcase in this scenario.
Thanks in Advance..

   <<Less
About | Sitemap | Contact