How do I run test cases in a list of slightly different jars?

I have a list of jar files containing several different versions of the same system.

I want to execute a set of test cases in each jar file, being able to get the results for each jar (via RunListener or something).

I am a bit confused about the class loading issues that are implied.

How can i do this?

0


source to share


2 answers


If you are using ant, the JUnit task takes a classpath.

<target name="test">
  <junit ...">
    <classpath>
      <pathelement path="${test.jar.path}" />
    </classpath>
    ...
  </junit>
</target>

      



You can use the antcall task to call your test object again with a different value for the test.jar.path property.

+2


source


If the jars support the same interface, then all you have to do is run each test with several different classes - each time with jars from a different version.

If you are using the Eclipse JUnit integration, simply create N run configurations, in each of which, on the classpath tab, specify the required jars.

If you want to do this programmatically, then I suggest you start with an empty classpath and use the URLClassLoader , giving it a different set of jars each time.



Something like that:

URLClassloader ucl = new URLClassLoader( list of jars from version1 );
TestCase tc = ucl.loadClass("Your Test Case").newInstance();
tc.runTest();

ucl = new URLClassLoader( list of jars from version2 );
TestCase tc = ucl.loadClass("Your Test Case").newInstance();
tc.runTest();

      

0


source







All Articles