sean
sean

Reputation: 1822

How to run a specific junit test in ant with parameter?

First, I have searched in stackoverflow, the following questions are related to mine, but not exactly what I wanted:

Suppose I have more than 100 test cases: A1Test... A100Test. I can make bachtest of junit in ant to run all of them. But I only want to run, say, A50Test. How I config my build.xml, so that I can run:

ant test A50Test

I don't want to create 100 targets for each of the test.

Upvotes: 0

Views: 2700

Answers (2)

eliam
eliam

Reputation: 1

but in my case, I need to add ".java" at the end of ${unit.test} make it worked.
hope to help someone. ^^

<batchtest fork="yes" todir="${output.test.dir}">
    <fileset dir="${source.test.dir}" includes="**/${unit.test}.java"/>
</batchtest>

Upvotes: 0

hoaz
hoaz

Reputation: 10143

Introduce property which defines test name you want to execute:

<property name="unit.test" value="*.java" />

Use this property in your batchtest:

<batchtest fork="yes" todir="${output.test.dir}">
    <fileset dir="${source.test.dir}" includes="**/${unit.test}"/>
</batchtest>

Pass value for this property to ant:

ant test -Dunit.test=A50Test

Upvotes: 2

Related Questions