Trouble finding jar during JUnit Tests
Idea Ver: 12.1.4
Project JDK: 1.6.0_20
JUnit Ver: 4.8.1
Scenario:
- Running a JUnit test involving JDBC with Oracle
- SQL Exception thrown during: DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
"java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@......"
- Confirmed that the jar: ojdbc14.jar is included in the classpath that is printed out on the console. The entire java command is 4847 bytes.
- Confirmed the URL, UserId, Passwd are correct
- Classpath for the JUnit tests is set to that of the module being tested.
-
- I dont see the issue when I invoke the JUnit test methods (setUp(), testCases...) from a non-JUnit test class in the main module. This test is a hacked up main().
- Also, no JDBC issues when running the app
Looks like ojdbc14.jar is not found/loaded while running the JUnit test.
Any advise?
请先登录再写评论。
Hello.
> Confirmed that the jar: ojdbc14.jar is included in the classpath that is printed out on the console.
If so, then the classes from jar are certainly included (no matter why). Then it may be a problem in test source.
A blind guess: can it be that Class.forName("oracle.jdbc.OracleDriver") call (or similar) is not performed in test run, while performed in main() run?
Regards,
Alexander.
Alexander,
My fault for trusting the test :(
You were absolutely right.
Thanks.