java - 使用 ant 在两个 jvm 中并行运行 junit

标签 java ant junit

我有大量的 junit,运行它们需要很长时间。但CPU和内存利用率只有30%左右。我无法在同一个 jvm 中的并行线程中运行 junit,因为它们不是线程安全的,并且无法修复它们。 据我所知,junit ant 任务启动单独的 jvm 来运行 junit。 是否可以从 ant 为 junit 运行几个 jvm?我认为这样的解决方案可以显着减少执行时间。

目前我使用这样的代码通过 ant 运行它们:

<for param="bundle" keepgoing="true">
<path>
    <dirset dir="${testdir}/plugins">
        <depth max="0"/>
    </dirset>
</path>
<sequential>

    <echo message="Running tests in bundle @{bundle}"/>
    <junit outputtoformatters="no" printsummary="yes" failureproperty="test.failed" maxmemory="512m" fork="yes"  forkmode="once">
        <classpath>
            <path refid="tests.classpath" />
        </classpath>

        <formatter type="xml" />
        <batchtest todir="${junit.result.dir}">
            <fileset dir="@{bundle}/src">
                <patternset refid="test.sources" />
            </fileset>
        </batchtest>
    </junit>
</sequential>

最佳答案

看看这个 http://ant.apache.org/manual/Tasks/parallel.html

The primary use case for is to run external programs such as an application server, and the JUnit or TestNG test suites at the same time. Anyone trying to run large Ant task sequences in parallel, such as javadoc and javac at the same time, is implicitly taking on the task of identifying and fixing all concurrency bugs the tasks that they run.

其中有这个例子

<parallel>
  <wlrun ... >
  <sequential>
    <sleep seconds="30"/>
    <junit fork="true" forkmode="perTest" ... >
    <wlstop/>
  </sequential>
</parallel>

编辑:更新了 forkmode 设置

关于java - 使用 ant 在两个 jvm 中并行运行 junit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13707359/

相关文章:

java - 在 Spring 中实现线程功能的最佳方式

java - Moshi 预期为 BEGIN_OBJECT 但为 BEGIN_ARRAY - 自定义转换器被忽略

java - 如何更改 Ant 任务中的 Java JDK 版本?

java - 有没有办法概括 Apache ANT 目标?

java - 在 eclipse 中运行 JUnit 测试后,我可以将结果导出为 XML 格式。如何使用 JUnit 命令行获取该 xml 文件?

java - 使用 Apache Commons Exec 时如何分别收集标准输出和标准错误?

java - Ant 包含外部项目

java - Java 接口(interface)应该只包含 getter 吗?

unit-testing - Spring Boot 在集成测试中使用 PowerMock 模拟静态方法

java - 我的应用程序在开始时崩溃并给我一个强制关闭错误