ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Price <epr...@ptc.com>
Subject Re: [OT] Re: unit test failure w/junit task
Date Thu, 06 Mar 2003 14:53:53 GMT


Keith Hatton wrote:
> Hi Erik,
> 
> Unfortunately, I've deleted the beginning of this thread. But I seem to remember that
it might have something to do with classloaders.
> 
> Normally, you (i.e. in this case, your 3rd party lib) would load native code in a static
{} block so that it only happens once during the lifetime of the VM.
> 
> However, if different classloaders come into play, the same class can be loaded multiple
times, so the static {} block gets executed multiple times. I'm getting out of my depth at
this point but I presume native code is unaware of the JVM classloader separation and that's
where things are going awry.
> 
> I would have expected that <junit fork="true" .../> would solve any issues though.
Suggest you check your classpath thoroughly. My best guess is that somehow two classloaders
are being asked to load the class that loads the DLL. This might actually be to do with JUnit
rather than Ant as it monkeys around with the classloaders too - can you run your JUnit class
through the JUnit GUI/command line interface, outside of Ant, to see what happens?

I tried just about every combination of the following factors:

- using fork="true" in my <junit> task
- not using fork="true" in my <junit> task
- putting remote connection step in setUp() in one TestCase class, 
storing the connection as a member of the instance
- putting remote connection step in non-static initializer in one 
TestCase class, storing the connection as a member of the instance
- putting remote connection step in non-static initializer in two 
TestCase classes
- Then all of the above with three TestCase classes making the remote 
connection.

And it turns out that if I'm using the remote connection in more than 
one TestCase class, I need to fork the process.  That seems to work.

(With only one TestCase class it seems that it was okay not to fork the 
tests.  Which makes me ask, since I didn't see the answer in the docs or 
the book: does this fork each test into its own JVM, or just a single 
separate JVM from Ant itself?)

Nonetheless, I will keep a watchful eye on unit tests I write that use 
the 3rd party library.

Thanks to everyone who helped out on this thread (and the JDw/A book for 
both the unit test w/ant tutorial and pointing out that forking a 
process generally requires including the java.class.path property into 
the classpath for the forked process).


Erik


Mime
View raw message