【问题标题】:Run junits in parallel in two jvms with ant用ant在两个jvm中并行运行junits
【发布时间】:2012-11-22 08:12:19
【问题描述】:

我有大量的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>

【问题讨论】:

标签: java ant junit


【解决方案1】:

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

的主要用例是运行外部程序,例如 作为应用程序服务器,以及 JUnit 或 TestNG 测试套件 同时。任何试图并行运行大型 Ant 任务序列的人, 比如javadoc和javac同时出现,隐含地承担着 识别和修复所有并发错误的任务 他们跑。

有这个例子

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

编辑:更新 forkmode 设置

【讨论】:

  • 文档说并行是使用线程实现的,对吧?这与提问者的要求不冲突吗?
  • 线程用于启动 JUNIT Ant 任务,这些任务又被配置为启动单独的 JVM 实例。这就是 fork="true" 的用途。
猜你喜欢
  • 1970-01-01
  • 2012-04-16
  • 2010-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多