【问题标题】:JUnit run tests inside a JARJUnit 在 JAR 中运行测试
【发布时间】:2012-09-02 19:10:03
【问题描述】:

我正在使用纯 JUnit 4 测试,并将它们编译在一些属于类路径的 jar 中。 我想在我的类路径中运行所有测试。

有办法吗?

我的任务如下:

<target name="test" description="All the tests">
    <junit fork="yes">
        <classpath> 
            <path refid="test.classpath" />
            <fileset dir="war/WEB-INF/lib/">
                <include name="*.jar"/>
            </fileset>
            <fileset dir="war/WEB-INF"/>
            <fileset dir="war"/>
        </classpath>
    <formatter type="plain" usefile="false" />

    </junit>
</target>

【问题讨论】:

    标签: java unit-testing testing ant junit


    【解决方案1】:

    下面的示例假设 JUnit 测试使用后缀“Test”命名,例如“MyClassTest.java”,并且 JUnit 4 jar 文件位于属性 lib.dir 指向的库目录中。对于每个包含已编译测试的 jar 文件,ZipFileSet 可用于在嵌套的&lt;batchtest&gt; 元素中选择测试类。 JUnit 4 jar 的路径包含在类路径中,以确保使用正确的版本。

    <target name="test" description="All the tests.">
      <junit fork="true">
        <classpath>
          <fileset dir="war/WEB-INF/lib/" includes="**/*.jar" />
          <fileset dir="${lib.dir}" includes="junit*.jar" />
        </classpath>
        <batchtest haltonfailure="true">
          <zipfileset src="war/WEB-INF/lib/test.jar" includes="**/*Test.class" />
        </batchtest>
        <formatter type="plain" usefile="false" />
      </junit>
    </target>
    

    【讨论】:

      猜你喜欢
      • 2013-01-10
      • 1970-01-01
      • 2017-08-30
      • 2012-08-23
      • 1970-01-01
      • 2010-12-08
      • 2014-12-12
      • 2012-06-02
      • 1970-01-01
      相关资源
      最近更新 更多