I have a list of jar files, all containing slightly different versions of the same system.
我有一个jar文件列表,所有这些文件都包含相同系统的略有不同的版本。
I want to execute a set of test cases on each jar file while being able to obtain the results for each jar (via RunListener or something like that).
我想在每个jar文件上执行一组测试用例,同时能够获得每个jar的结果(通过RunListener或类似的东西)。
I am a bit confused with the class loading problems that are implied.
我对隐含的类加载问题有点困惑。
How can I nicely do this ?
我怎么能很好地做到这一点?
2 个解决方案
#1
If you are using ant, the JUnit task takes a classpath.
如果您使用ant,则JUnit任务采用类路径。
<target name="test">
<junit ...">
<classpath>
<pathelement path="${test.jar.path}" />
</classpath>
...
</junit>
</target>
You can use the antcall task to call your test target repeatedly with a differed value for the test.jar.path property.
您可以使用antcall任务以test.jar.path属性的不同值重复调用测试目标。
#2
If the jars maintain the same interface, then all you have to do is run each test with a slighly different classpath - each time with jars from another version.
如果jar保持相同的接口,那么你所要做的就是用一个略有不同的类路径运行每个测试 - 每次都使用另一个版本的jar。
If you're using Eclipse JUnit integration, just create N run configurations, in each one in the classpath tab specify required jars.
如果您正在使用Eclipse JUnit集成,只需创建N个运行配置,在类路径选项卡中的每个配置中指定必需的jar。
If you want to do it programmatically, then I suggest you start with empty classpath and use URLClassLoader, giving it a different set of jars each time.
如果你想以编程方式进行,那么我建议你从空类路径开始并使用URLClassLoader,每次给它一组不同的jar。
Something like this:
像这样的东西:
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();
#1
If you are using ant, the JUnit task takes a classpath.
如果您使用ant,则JUnit任务采用类路径。
<target name="test">
<junit ...">
<classpath>
<pathelement path="${test.jar.path}" />
</classpath>
...
</junit>
</target>
You can use the antcall task to call your test target repeatedly with a differed value for the test.jar.path property.
您可以使用antcall任务以test.jar.path属性的不同值重复调用测试目标。
#2
If the jars maintain the same interface, then all you have to do is run each test with a slighly different classpath - each time with jars from another version.
如果jar保持相同的接口,那么你所要做的就是用一个略有不同的类路径运行每个测试 - 每次都使用另一个版本的jar。
If you're using Eclipse JUnit integration, just create N run configurations, in each one in the classpath tab specify required jars.
如果您正在使用Eclipse JUnit集成,只需创建N个运行配置,在类路径选项卡中的每个配置中指定必需的jar。
If you want to do it programmatically, then I suggest you start with empty classpath and use URLClassLoader, giving it a different set of jars each time.
如果你想以编程方式进行,那么我建议你从空类路径开始并使用URLClassLoader,每次给它一组不同的jar。
Something like this:
像这样的东西:
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();