0

I want to use specified test classes available in my repository with sfdx force deploy command. I can include it using -l RunSpecifiedTests -r TestClass1,TestClass2. However, I had to manually write the test class name in case of any additions. Can there be any such parameter in sfdx or some other way I can import all test cases present in the repository so that while running in prod it only runs the specified ones.

2 Answers 2

0

Short answer, no.

If you want to select specific tests to be run in a deployment, you currently must explicitly type them all out in the -r flag.

It'd be nice if we had the ability to specify a test suite to run (on deployment). From what I recall though, sfdx is just an interface that wraps the metadata api (so getting test suite support would also require the metadata api team, which is a separate team, to also do work).

+edit: references
https://github.com/forcedotcom/cli/issues/621 (is a wrapper for the metadata api)
https://github.com/forcedotcom/cli/issues/1836 (possibly being worked on at time of writing?)

1
  • Oddly, you can run suites (which also uses mdapi) via sf apex test run --suite-names, but apparently isn't an option for deploys. I guess one could write a script for it, though.
    – sfdcfox
    Jun 6, 2023 at 16:40
0

You could use the following command in a shell/bash terminal to collect all the test classes in a comma-separated string variable:

export TESTS=$(find force-app -name "*Test.cls" -type f -exec basename {} \; | sed 's/\..*$//' | paste -sd ',')

This assumes the file name of all test classes end in "Test.cls".

Then you can use it in a deploy command. For example:

sfdx force:source:deploy --sourcepath force-app --testlevel RunSpecified --runtests $TESTS
1
  • I know that you say shell/bash, but I also think that it's good to call out that this is linux-specific (might also work on Mac).
    – Derek F
    Apr 17 at 14:02

You must log in to answer this question.

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