tags:

views:

272

answers:

2

I'm not very good w/ ant, but we're using it as a build tool. Right now, we can run "ant test" and it'll run through all the unit tests.

However, I'd love to be able to do "ant test some_module" and have it accept "some_module" as a parameter, and only test that. I haven't been able to find how to pass command line args to ant - any ideas?

Oh, and we're running Linux (Centos)

Thanks, Jon

+4  A: 

One solution might be as follows. (I have a project that does this.)

Have a separate target similar to test with a fileset that restricts the test to one class only. Then pass the name of that class using -D at the ant command line:

ant -Dtest.module=MyClassUnderTest single_test

In the build.xml (highly reduced):

<target name="single_test" depends="compile" description="Run one unit test">
    <junit>
        <batchtest>
            <fileset dir="${test.dir}" includes="**/${test.module}.class" />
        </batchtest>
    </junit>
</target>
martin clayton
Martin has understated the case here a bit. According to the ant FAQ, properties are THE way to do what you want. See http://ant.apache.org/faq.html#passing-cli-args for details
vkraemer
A: 

What about using some conditional in your test target and the specifying -Dcondition=true?

<target name="test" depends="_test, _test_if_true>
   ...
</target> 

<target name="_test_if_true" if="condition">
   ...
</target>

<target name="_test" unless="condition">
   ...
</target>

Adapted a bit from the ant faq.

Qberticus