tags:

views:

616

answers:

3

I have an Ant script with a junit target where I want it to start up the VM with a different working directory than the basedir. How would I do this?

Here's a pseudo version of my target.

<target name="buildWithClassFiles">
 <mkdir dir="${basedir}/UnitTest/junit-reports"/>
 <junit fork="true" printsummary="yes">
  <classpath>
   <pathelement location="${basedir}/UnitTest/bin"/>
   <path refid="classpath.compile.tests.nojars"/>
  </classpath>
  <jvmarg value="-javaagent:${lib}/jmockit/jmockit.jar=coverage=:html"/>
  <formatter type="xml" />
  <test name="GlobalTests" todir="${basedir}/UnitTest/junit-reports" />
 </junit>

</target>
+2  A: 

Have you tried:

 <junit fork="true" printsummary="yes" dir="workingdir">
James Van Huis
You might want to also set forkonce="true" so you don't fork on every test.
Dave
A: 
<batchtest fork="yes" todir="${reports.tests}">
 <fileset dir="${src.tests}">
  <include name="**/*Test*.java"/>
  <exclude name="**/AllTests.java"/>
 </fileset>
</batchtest>
01
A: 

I think the other answers might be overlooking the fact that you want the working directory to be specified, not just that you want to run junit on a particular directory. In other words, you want to make sure that if a test creates a file with no path information, it is from the base directory you are specifying.

Try to pass in the directory you want as a JVM arg to junit, overriding user.dir:

 <junit fork="true" ...>
   <jvmarg value="-Duser.dir=${desired.current.dir}"/>
    ....
matt b
Actually, my answer above is resetting the directory. The "dir" argument of the junit task, when used in combination with "fork", will launch the VM in the specified directory.
James Van Huis