简体   繁体   English

如何在稍微不同的jar列表上运行测试用例?

[英]How to run test cases on a list of slightly different jars?

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 ? 我该怎么做呢?

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属性的不同值重复调用测试目标。

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个运行配置,然后在classpath选项卡的每个配置中指定所需的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 ,每次都给它一组不同的罐子。

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM