Unnamed
Unnamed

Reputation: 1790

Use Ant to only run specific JUnit tests

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?

Upvotes: 7

Views: 3972

Answers (2)

datalost
datalost

Reputation: 3773

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

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 692191

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>

Upvotes: 3

Related Questions