簡體   English   中英

如何在ant build.xml中設置junit測試?

[英]How do I set up a junit test in an ant build.xml?

測試名稱:simpeltest.java

位置:com.prog.simpletest

import org.junit.test

public class simpletest
{
  @Test
  public void check()
  {
     assert(true);
  }
}

build.xml文件

如何設置此人(build.xml)來運行測試?

您需要正確設置ant構建。 有一個build.properties文件來聲明公用文件夾,然后在您的ant文件中執行類似的操作。

 <target name="test.java" depends="build.java.src, build.java.test">
    <mkdir dir="${java.test.reports.path}" />
    <junit haltonfailure="no" printsummary="true">
      <classpath>
        <path refid="test.run.classpath" />
        <pathelement location = "${java.src.build.path}" />
      </classpath>
      <!-- add to see errors on console while running junit tests.
      <formatter type="brief" usefile="false" />    
      -->
      <formatter type="xml"/>
      <batchtest fork="yes" todir="${java.test.reports.path}">
        <fileset dir="${java.test.build.path}/">
          <include name="**/*Test*.class"/>
          <exclude name="**/*$*.class"/>
        </fileset>
      </batchtest>
    </junit>
  </target> 

使用JUnit任務

有關JUnit Task的文檔應該會有所幫助。 這就是我用來幫助我在Ant中設置junit測試的功能。

這是我的螞蟻腳本的基本樣子:

<junit fork="yes" forkmode="perBatch">
  <jvmarg value="-Xmx600M"/>
  <!-- other jvmargs -->

  <classpath>
    <pathelement path="${binariesPath}" />
    <pathelement path="${unitTestBinariesPath}" />
  </classpath>

  <batchtest todir="${dir.tmpBuildDir}\JUnitTest">
    <fileset dir="${dir.unitTestBinaries}">
      <include name="**/*Test.class" />
    </fileset>
  </batchtest>
</junit>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM