[SalesForce] How to run all the test classes in the org using Ant

I want to run all the test classes in my org excluding any test classes from Managed package installation using Force migration tool aka ANT.

Looks like there used to be a task called sf:compileAndTest(as mentioned in this question) but I don't see that any more in salesforce official documentation here. May be this task is removed in the latest release.

Does anybody know a way to run all test classes(unmanaged) in the org using ANT?

P.S: I don't want to make any deployment. I just want to run the test classes to see what is the test coverage level. I don't want to run all the test classes from UI.

Best Answer

yes that is correct. sf:compileAndTest is no longer supported but you can run all test from sf:deploy task with the runAllTests="true" attribute, you don't need to actually deploy anything, though you will need a package.xml as per the documentation.

<!-- Shows check only; never actually saves to the server -->
<target name="deployCodeCheckOnly">
       <sf:deploy username="${sf.username}" password="${sf.password}"
        sessionId="${sf.sessionId}" serverurl="${sf.serverurl}"
        maxPoll="${sf.maxPoll}" deployRoot="dummy" testLevel="RunAllTestsInOrg"
        checkOnly="true"/>
</target>

Package.xml

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <version>35.0</version>
</Package>