My team sometimes has a release process that requires deploying multiple packages in stages. We want to make sure that the system remains stable at the end of each of these deployments by running a few sanity tests, but we don't care about the code coverage until we deploy the last package.

Is there a way to run an <sf:deploy> target that runs a few test classes (and fails if those tests fail), but does not fail if code coverage is not reached for the deployed classes?

  • have you tried run specific test though you can't bypass overall code coverage, you need overall code coverage to 75%
    – Himanshu
    Feb 7, 2018 at 20:51
  • Yes, I tried that. Sadly, bypassing the code coverage check is exactly what I need. I tried deploying and running the tests class separately and that worked - because the test class is the only one that's checked for coverage and of course it runs completely. But I need this to happen in the same deploy so that I can roll back the other files if the tests fail. Feb 8, 2018 at 19:47

2 Answers 2


By default, no tests are run in a deployment to a non-production organization, such as a sandbox or a Developer Edition organization.

To specify tests to run in your development environment, set a testLevel deployment option. For example, to run local tests in a deployment and to exclude managed package tests, add the testLevel="RunLocalTests" parameter to the deploy target.

<target name="deployCode">
<sf:deploy username="${sf.username}" password="${sf.password}"
sessionId="${sf.sessionId}" serverurl="${sf.serverurl}"
deployroot="codepkg" testLevel="RunLocalTests">

Running a Subset of Tests in a Deployment

If the code coverage of an Apex component in the deployment is less than 75%, the deployment fails. If one of the specified tests fails, the deployment also fails. We recommend that you test your deployment in sandbox first to ensure that the specified tests cover each component sufficiently. Even if your organization’s overall code coverage is 75% or more, the individual coverage of the Apex components being deployed can be less. If the code coverage requirement isn’t met, write more tests and include them in the deployment. To run a subset of tests, add the testLevel="RunSpecifiedTests" parameter to the deploy target. Specify each test class to run for a deploy target in a child element within the sf:deploy element. Add the test class name within the tags. Add as many runTest tags as you need, one for each test class.

<target name="deployCode">
<sf:deploy username="${sf.username}" password="${sf.password}"
sessionId="${sf.sessionId}" serverurl="${sf.serverurl}"
deployroot="codepkg" testLevel="RunSpecifiedTests">

Refer: Force.com Migration Tool Guide

  • Thanks Santanu, but this is part of the official documentation and I had already gone through that. In our case, we need to have tests make the deployment fail but code coverage NOT make the deployment fail, which the official documentation does not mention. Feb 8, 2018 at 0:32
  • Perform Run local test Feb 8, 2018 at 0:48
  • Using runLocalTests would run all local tests (which would take 1+ hours), but we need to run only a few selected of our test classes (that we know would run in a couple minutes). Feb 8, 2018 at 1:28
  • 1
    if you need to run few selected classes then RunSpecifiedTests. Now here Salesforce expects each class must have 75% coverage Feb 8, 2018 at 1:30
  • I'm looking for the same solution. I'd like to perform a deployment and execute all tests with a flag to opt out of collecting code coverage. I'm aware that we can do it manually as we can see on Salesforce Summer ’18 Release Notes. (releasenotes.docs.salesforce.com/en-us/summer18/release-notes/…). Seems that this option isn't available yet, is it? Aug 28, 2018 at 10:07

You can opt out code coverage by

Developer Console > Test > New Run > Settings > Tick "Skip Code Coverage"

Skip Code Coverage

Source: https://releasenotes.docs.salesforce.com/en-us/summer18/release-notes/rn_apex_opt_out_code_coverage.htm.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .