aspose file tools*
The moose likes Testing and the fly likes JUnit & JDBC problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JUnit & JDBC problem" Watch "JUnit & JDBC problem" New topic
Author

JUnit & JDBC problem

Paul Ramsden
Greenhorn

Joined: Sep 22, 2000
Posts: 28
I am trying to test some classes which use JDBC connections. The first TestCase to run is able to get a connection for each test it runs, but all later TestCases exit with 'SQLException - No suitable driver'. The tests are being run in batch mode using ANT.
I guess it has something to do with class loading. Perhaps a new class loader for each test?
My test code run in 2 successive Junit tests
reproduces the problem.

Does anyone have any ideas?
Paul
[ July 15, 2003: Message edited by: Paul Ramsden ]
Paul Ramsden
Greenhorn

Joined: Sep 22, 2000
Posts: 28
I have found a way around the problem.
I added fork="yes" to the junit task in ANT.
In spite of that, I would be glad to hear from anyone with insight into class loading in Junit.
Paul
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
Which test runner are you using? I know people often have problems with the GUI version...
Paul Ramsden
Greenhorn

Joined: Sep 22, 2000
Posts: 28
ANT is running in text mode, the JUnit task is too.
Barry Hawkins
ranger
Greenhorn

Joined: Jan 13, 2004
Posts: 8
I, too, am experiencing this problem, and setting fork="yes" in my <junit> task is what resolved the issue. I also happen to be using the IBM DB2 Connect JDBC Type 2 driver like you are in the code above. As you know, Type 2 drivers interface heavily with native code on the client. You may find that the "net" driver for DB2 (Type 4, IIRC) works without the fork setting on the <junit> task, as it does not interface with native code libraries. The issue appears to be related to Apache Bug Report #19275: <junit> fails when test classes load native code. Hope this helps some other folks.


Barry Hawkins<br />All Things Computed<br />site: <a href="http://www.alltc.com" target="_blank" rel="nofollow"><br />weblog: [URL=http://www.yepthatsme.com]www.yepthatsme.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JUnit & JDBC problem