Does Junit run each test suite in separate classLoader or even separate JVM?
Here is a situation. I have multiple test suites (say suite 1 and suite 2). I'm using ant to run Junit on these suites.
test cases in each suite depends on a class (say classA) in thier own class path but the classA has diffrent version:
classpath for suite 1: has classA (version 1)
classpath for suite 2: has classA (version 2)
the 2 versions of classA has same package name and class name but content is diffrent (diffrent version). suite 1 and 2 have thire own class path.
Question is, does Junit run (through ant) each test suite in separate classLoader? the concern is, if not, the suite 1 load classA version 1, then before running suite2, it won't unload version 1 of classA and reload version 2 of classA - is this a valid concern? if so, is there any way to ensure the correct version of classA load for each test suite?
I believe it runs them in different classloaders, yes; at the very least it runs each unit test with a new instance of the test suite class. If that is a problem for you, you might want to switch to TestNG which has a leaner lifecycle in my opinion.
The test shows it's not stable. sometimes from version 1 some times from version 2.
I wonder if JUnit has any document clarify this as I thought this is common issue. if one test suite interfere by classes loaded in another suite and causing failure, it would be very hard to debug to find out root cause - thought Junit need to clarify this.