Run Specific Tests with Ant Deploy specified by command line or file
Was able to do this using ant's scripting capability. Now you can do ant deploy -Ddir=src -Dtests=Class1,Class2,Class3
<target name="deploy">
<script language="javascript"><![CDATA[
var deployTask = project.createTask('antlib:com.salesforce:deploy');
deployTask.setUsername(project.getProperty("sf.username"));
deployTask.setPassword(project.getProperty("sf.password"));
deployTask.setServerURL(project.getProperty("sf.serverurl"));
deployTask.setDeployRoot(project.getProperty("dir"));
deployTask.setTestLevel(project.getProperty("testLevel"));
deployTask.setMaxPoll("300");
var tests = project.getProperty('tests');
if (tests) {
deployTask.setTestLevel('RunSpecifiedTests');
tests = tests.split(',');
for (var i = 0; i < tests.length; i++) {
var runTest = java.lang.Class.forName(
"com.salesforce.ant.DeployTask$CodeNameElement"
).newInstance();
runTest.addText(tests[i]);
deployTask.addRunTest(runTest);
}
}
deployTask.perform();
]]></script>
</target>