Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Ant to only run specific JUnit tests

Tags:

java

junit

ant

We currently have a project set up and have 4 teams working on different parts of it. I am wanting to have 5 ant targets to run. One for each team and one additional for production. But I would like to set an enum in my tests to determine which tests are run.

For example, if a test has.

runConfiguration = RunConfigurations.PRODUCTION;

Then I would run it to only run for that specific ant target. And other tests would run if I did:

runConfiguration = RunConfigurations.TEAM1;

etc.

Is it possible in ant to create a batchtest to only run test with a specific enum value like this? Or is there perhaps another method to accomplish the same purpose?

like image 421
justspamjustin Avatar asked Sep 14 '11 18:09

justspamjustin


2 Answers

No, you won't be able to do that. The resource collection simply defines the set of java or class files to run as test.

Why don't you simply organize your tests in packages, or even have one source/target directory per set of tests?

<batchtest ...>
    <fileset dir="testclasses">
        <include name="com/foo/bar/team1/**/*.class"/>
    </fileset>
</batchtest>

or

<batchtest ...>
    <fileset dir="testclasses/team1">
        <include name="**/*.class"/>
    </fileset>
</batchtest>
like image 154
JB Nizet Avatar answered Sep 20 '22 13:09

JB Nizet


What if using TestSuite? Then use ant to execute only desired TestSuites that you want in different occasions.

like image 36
datalost Avatar answered Sep 20 '22 13:09

datalost