Database Connectivity in junit plugin test

WindowTester allows you to easily create and run unit tests for every GUI they build. It can also be used to generate system level tests.

Moderators: gnebling, Eric Clayberg, Dan Rubel, keertip, Phil Quitslund

Database Connectivity in junit plugin test

Postby Evelin » Sat Aug 28, 2010 1:53 am

Hi,
I want to connect to a mysql db for reporting the passes/failures of automation suite.
I am not able to do so when I run test case as junit-plugin test.
I tried with a simple testfile to check this connectivity.
If I run the test case as a simple junit test , the connection is established.
The same code fails to connect to db when I run it as a junit-plugin test.
I have to run my automation suite as junit-plugin test itself. Help appreciated.

This is the test case that I used for checking connection.

public class sampltest extends UITestCaseSWT {
public void testconnection()
{
ResultsManager rm = new ResultsManager();
rm.createMySQLConnection();
rm.closeConnection();
}
}

Result manager class functions:

public class ResultsManager {
Connection c = null;
Statement stmnt1,stmnt = null;
ResultSet rs = null;

public void createMySQLConnection()
{
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
c = DriverManager.getConnection("jdbc:mysql://<ip>:<port>",
"username", "pwd");

if(!c.isClosed())
System.out.println("Successfully connected to " +
"MySQL server using TCP/IP...");
stmnt = c.createStatement();

}
catch(Exception e)
{
System.err.println("Exception: " + e.getStackTrace());
e.printStackTrace();
try {
if(c != null)
c.close();
} catch(SQLException e1) {
e.printStackTrace();
}
}
}

public void closeConnection()
{
try {
c.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

I get this Exception when I run the above as junit-plugin test.

Exception: [Ljava.lang.StackTraceElement;@711407
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:483)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:399)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at ResultsManager.createMySQLConnection(ResultsManager.java:51)
at sampltest.testconnection(sampltest.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at com.windowtester.runtime.common.UITestCaseCommon.access$0(UITestCaseCommon.java:1)
at com.windowtester.runtime.common.UITestCaseCommon$2.run(UITestCaseCommon.java:136)
at com.windowtester.runtime.common.UITestCaseCommon$3.run(UITestCaseCommon.java:157)
at com.windowtester.internal.runtime.junit.core.SequenceRunner$1.run(SequenceRunner.java:46)


I have added the mysql driver jar in the library.The connection is successfully established when the test is run as junit test and fails when run as junit-plugin test.Any pointers on what is going wrong here will be really really helpful.

-Evelin
Evelin
 
Posts: 1
Joined: Sat Aug 28, 2010 1:34 am

Re: Database Connectivity in junit plugin test

Postby keertip » Tue Sep 07, 2010 12:44 pm

Are the plugins needed for mysql access included in the Plug-ins tab in the JUnit Plug-in test launch configuration? From the error message, looks like the plugins are not in the launch configuration.
keertip
Moderator
 
Posts: 221
Joined: Thu Mar 15, 2007 10:26 am


Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest

cron