Run specific apex tests during "sfdx force:source:deploy"

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

https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_source.htm


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.