Since summer 19, sfdx force:source:deploy allows us to push source format meta-data into static orgs and production. The Commands are introduced here

However when I check the help of sfdx force:source:deploy, it seems the lowest number of Apex tests that you can run is --testlevel RunLocalTests.

Is it possible to set it to run only specific apex tests when deploying into a production org?


Now with the latest sfdx update(7.21.0) you can run 'sfdx force:source:deploy' command with specific test classes. Check below command.

sfdx force:source:deploy -p "./PathToMetadata" -l RunSpecifiedTests -r TestClass1,TestClass2 -w 33 --verbose --loglevel fatal


  • 1
    Additionally, you can run specific methods from the test class, instead of the default "all methods" - RunSpecifiedTests -r TestClass1.method1,TestClass2 Jan 6 at 18:21

force:source:deploy does let you run specific tests by setting --testlevel to RunSpecifiedTests and then specifying the tests with the --runtests argument.

So you could do something like sfdx force:source:deploy --checkonly --sourcepath force-app --targetusername production-org --testlevel RunSpecifiedTests --runtests MyUnitTests to do a validation and run specific tests.

  • what is MyUnitTests its a test package name?
    – ShreyasD
    May 25 '20 at 18:34
  • 1
    No, it's the name of a test class. If you want to run tests from multiple classes you can use a comma separated list instead. May 26 '20 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.