【问题标题】:Running junit ant-task without build.xml在没有 build.xml 的情况下运行 junit ant-task
【发布时间】:2012-07-11 00:40:20
【问题描述】:

我正在尝试弄清楚如何在实际上不需要 build.xml 的情况下运行 ant 任务。 特别是我想用格式化程序运行JUnit 任务。在 xml 格式中,如下所示:

<junit printsummary="true" errorProperty="test.failed" failureProperty="test.failed">
    <classpath refid="run.class.path" />

    <!-- console log -->
    <formatter type="xml" classname="be.x.SFFormatter" />

    <test name="be.x.SF" outfile="result" todir="${build.output.dir}" />
</junit>

它在运行 ant 脚本时有效,但我想让我的应用程序作为可运行的 jar 运行。 从 Java 运行测试很容易:

    JUnitCore junit = new JUnitCore();
    testResult = junit.run(SeleniumFramework.class);

但是,我很难弄清楚如何让格式化程序真正工作。 格式化程序是 org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter 类型的,所以我怀疑我是否可以在不运行 ant 的情况下将其插入某个地方。

以前有没有人做过类似的事情? 谢谢!

【问题讨论】:

    标签: java deployment ant jar junit


    【解决方案1】:

    蚂蚁不会做任何魔法。它所做的只是读取 XML 文件,创建其中指定的 bean,然后按照 Task API (org.apache.tools.ant.Task) 执行方法。

    因此,您只需在代码中执行相同操作即可。不要忘记创建一个Project :-)

    【讨论】:

    • 我决定将构建文件捆绑到我的 jar 中并在内部运行它。有点难过,这让我的最终产品现在依赖于 ant,但目前我可以忍受它
    【解决方案2】:

    您可以通过 Groovy 使用 Ant 来避免 xml 语法。
    请参阅 => Using Ant from Groovy 了解详情。

    【讨论】:

      猜你喜欢
      • 2021-07-13
      • 2023-04-04
      • 2012-02-06
      • 1970-01-01
      • 2015-06-24
      • 1970-01-01
      • 2014-01-11
      • 2015-03-02
      • 2013-05-05
      相关资源
      最近更新 更多