stackoverflow
stackoverflow

Reputation: 19434

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

Test Name: simpeltest.java

Location: com.prog.simpletest

import org.junit.test

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

build.xml

how do I set this guy (build.xml) up to run the test?

Upvotes: 0

Views: 8458

Answers (3)

nicholas.hauschild
nicholas.hauschild

Reputation: 42849

This documentation for JUnit Task should be helpful. It is what I used to help me setup junit tests in Ant.

This is what my ant script basically looked like:

<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>

Upvotes: 1

Ravi Bhatt
Ravi Bhatt

Reputation: 3163

You need to setup ant build properly. Have a build.properties file to declare common folders and then do something like this in your ant file..

 <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> 

Upvotes: 2

kgautron
kgautron

Reputation: 8263

Use the JUnit task.

Upvotes: 1

Related Questions