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?

2 Answers 2


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, 2021 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, 2020 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, 2020 at 22:06
  • can we make --runtests MyUnitTests this part of command dynamic? Like point to a specific folder. Apr 18 at 9:55
  • The --runtests parameter only takes a comma separated list of tests, so there's nothing built into the CLI for passing in a folder - but if you have the tests you want to run in a specific folder there's nothing stopping you from using a script to build a comma separated list of test class names from the files in that folder and passing that list to the command. Apr 20 at 15:32

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.