You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Paul Elschot <pa...@xs4all.nl> on 2005/01/18 18:07:54 UTC

Re: Enabling assertions without forking for each test. Can I fork junit itself?

Domique, Ivan,

On Tuesday 18 January 2005 10:55, Ivan Ivanov wrote:
> Hello, Paul,
> --- Paul Elschot <pa...@xs4all.nl> wrote:
> > 
> > I upgraded ant from 1.6b2 to 1.6, and according to
> > the docs the
> > above forkmode should do what I need.
> > 
> > For the moment the compilation of the test code
> > fails, because
> > the junit.framework package does not exist for the
> > compiler
> > after the ant upgrade.
> 
> You should download Junit from junit.org and you have
> three ways to integrate junit.jar with Ant:
> 1) Place junit.jar in $ANT_HOME/lib. I suppose you had
> it there in your old Ant version.
> 2) Place junit.jar in $HOME/.ant/lib. Since ant 1.6 it
> will be automatically picked up for your build
> process.
> 3) Place in somewehere on your filesystem, say
> /data/my_third_party_jars/junit.jar and start ant with
> -lib option:
> ant -lib /data/my_third_party_jars
> 
> I personalyy use mainly 2).

I forgot I had added the junit (3.8.1) jar to my 1.6b2 ant lib directory.
Copying it to the 1.6.2 ant lib dir solved the problem.

Also, in the junit task, using forkmode="once" halved the time
taken for the 10 short tests (from 8 to 4 seconds), and
still allowed to use assert via jvmarg, so the problem is solved.

Thanks,
Paul Elschot.

P.S.
This is the ant test task now from build.xml, with the property test.fork="yes":

  <target name="test" depends="compile-test" if="junit.present"
    description="Runs unit tests"
  >
    <mkdir dir="${junit.output.dir}"/>
    <junit
        printsummary="off"
        haltonfailure="${test.haltonfailure}"
        errorProperty="tests.failed"
        failureProperty="tests.failed"
        fork="yes"
        forkmode="once"
    >
      <jvmarg value="-enableassertions:${test.assert.package}..."/>
      <classpath refid="junit.classpath"/>
      <sysproperty key="dataDir" file="src/test"/>
      <sysproperty key="tempDir" file="${build.dir}/test"/>
      <formatter type="xml"/>
      <formatter type="brief" usefile="false"/>
      <batchtest fork="${test.fork}" todir="${junit.output.dir}" unless="testcase">
        <fileset dir="src/test" includes="**/Test*.java"/>
      </batchtest>
      <batchtest fork="${test.fork}" todir="${junit.output.dir}" if="testcase">
        <fileset dir="src/test" includes="**/Test*${testcase}.java"/>
      </batchtest>
    </junit>

    <fail if="tests.failed">Tests failed!</fail>
  </target>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org