oracle.jdbc.OracleDriver found in application, not in Test
When I connect to the OracleDriver in the application, everything is fine. But when I want to connect to run the JUnit Tests, I got a ClassNotFoundException. And I do exactly the same!
I have the ojbc added to the library and the testlibrary.
public JDBCDataStorage(boolean production) throws DataStorageException {
this.production = production;
try {
rb = (PropertyResourceBundle) PropertyResourceBundle.getBundle("app.control.database.JDBCcon开发者_Python百科fig");
Class.forName(rb.getString("driver"));
} catch (ClassNotFoundException e) {
throw new DataStorageException("Something went wrong in new JDBCDataStorage()" + ": " + e.getMessage());
}
DriverManager.setLoginTimeout(3);
}
Check for two things
- That
rb.getString("driver")
actually returns the FQCN of your driver. - That the driver JAR is in classpath of your test application
Try adding the Oracle JDBC driver jarfile to the classpath of the JUnit test. If you're running the unit test in Eclipse, add the driver jarfile to the User Entries in the Run Configuration of the JUnit test.
精彩评论