【问题标题】:ant task to run JUnit tests from a jar (but only files that have tests!)从 jar 运行 JUnit 测试的 ant 任务(但仅限具有测试的文件!)
【发布时间】:2018-06-06 07:28:28
【问题描述】:

我们在自定义框架中使用 JUnit 来测试应用程序的行为。我们实际上并没有进行单元测试,只是利用了 JUnit。

我创建了一个 ant 任务来运行 jar 文件中的所有测试,但不幸的是它试图将 everything 作为 JUnit 测试运行。由于 jar 文件包含除测试之外的其他内容(它包含支持框架),这是一个问题。

有没有办法让 junit 任务只运行标记为测试的东西(我们使用@Test)?

目前我的 ant 任务如下所示:

<target name="test">
    <junit printsummary="yes" haltonfailure="no">
        <classpath refid="library.third-party.classpath" />
        <classpath>
            <pathelement location="${basedir}/build/jar/fidTester.jar" />
        </classpath>

        <formatter type="plain" />
        <formatter type="xml" />

        <batchtest fork="no" todir="${basedir}/reports">
            <zipfileset src="${basedir}/build/jar/fidTester.jar" includes="**/tests/**/*.class" />
        </batchtest>

    </junit>
</target>

【问题讨论】:

    标签: junit ant


    【解决方案1】:

    来自Ant JUnit Task documentation

    skipNonTests

    不要将任何不包含 JUnit 测试的类传递给测试 亚军。这可以防止非测试在测试中显示为测试错误 结果。通过查找 @Test 注释来识别测试 不扩展的具体类中的任何方法 junit.framework.TestCase,或用于具有名称的公共/受保护方法 从扩展的具体类中的测试开始 junit.framework.TestCase。用 JUnit 4 标记的类 org.junit.runner.RunWith 或 org.junit.runner.Suite.SuiteClasses 注释也传递给 JUnit 执行,任何类也是如此 使用公共/受保护的无参数 suite() 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-29
      • 2015-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-30
      相关资源
      最近更新 更多