0

I'm trying to understand the use of the -l RunSpecifiedTests flag in the sfdx force:apex:test:run command. The following commands returns the same results:
sfdx force:apex:test:run -l RunSpecifiedTests -t "MyTestClass.myTestMethod" -r human
sfdx force:apex:test:run -t "MyTestClass.myTestMethod" -r human
So, what the point in using -l RunSpecifiedTests?

Thank you all in advance,
Lior.

2 Answers 2

0

In this context the -l parameter isn't required at all. If you're running specified tests then this is redundant, however it is useful with the values ( -l RunLocalTests and -l RunAllTestsInOrg) as it means you don't have to manually list all the tests in your org.

0

For us end-users, there doesn't appear to be a point (other than maintaining a bit of consistency between commands).

Specifying the test level is more about giving us access to run all/local tests in an org. This is something we wouldn't be able to easily do without having the -l/--testLevel flag. Test Suites could technically pick up the slack, but an "all local tests" test suite is a pain to maintain (and to build in the first place) and would be problematic for packaging.

On the back-end side of things though, it wouldn't surprise me if the REST/SOAP API endpoints require the test level to be set (and that it's automatically set appropriately when using -t, -n, or -s flags)

+edit:
yep, specifying -t, -n, or -s causes the testLevel to be automatically set to "RunSpecifiedTests" (and "RunLocalTests" is the default), which we can see by looking at getTestLevelFromFlags() in lib/commands/force/apex/test/run.js

You must log in to answer this question.

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