1

I've created my test suite and trying to run using sfdx command. this way, i'm getting error while running below command

test file

<?xml version="1.0" encoding="UTF-8"?> <ApexTestSuite xmlns="http://soap.sforce.com/2006/04/metadata"> <testClassName>box.BoxAuthResponseTests</testClassName> <testClassName>box.BoxBase64Tests</testClassName> <testClassName>BoxPlatformTests</testClassName> <testClassName>BoxWebLinkTests</testClassName> </ApexTestSuite> 

Command:

sfdx force:apex:test:run -s "force-app/main/default/testSuites/vinay.testSuite-meta.xml" -c -v --json 

Error :

{ "status": 1, "name": "Error", "message": "Select a result format when specifying code coverage", "exitCode": 1, "commandName": "Run", "stack": "Error: Select a result format when specifying code coverage\n at Run.<anonymous> 

1 Answer 1

2

The --json flag specifies the format of the command's output, but not the format for the code coverage. That requires a separate flag.

When you use -c, the -r or --resultFormat flag must be used (specify either human, tap, junit, or json for it)

So your command should look like sfdx force:apex:test:run -s "force-app/main/default/testSuites/vinay.testSuite-meta.xml" -c -v -r human --json

Using the path of the testsuite in your sfdx project isn't something I had seen before, and doesn't make too much sense. Based on the new error you're getting, this is also incorrect syntax.

Taking a look at the error I get, I see sfdx trying to execute a query based on the input given.

nested exception is: common.exception.ApiQueryException: ApexTestSuite WHERE TestSuiteName in ('.\force-app\main\default\testSuites\MyIntegration')

Tests are run on Salesforce's servers, so they have no access to a file on your local computer. Your testSuite needs to be deployed in your target org prior to running tests based on it. Therefore, the correct syntax is to simply use the name of the test suite instead of the path, e.g. sfdx force:apex:test:run -s vinay -c -v -r human --json

4
  • Thanks Derek, I tried to run as per you suggestion but still getting error, sfdx force:apex:test:run -s "force-app/main/default/testSuites/vinay.testSuite-meta.xml" -c -v -r human --json { "status": 1, "name": "INVALID_INPUT", "message": "Invalid ID or name: force-app/main/default/testSuites/vinay.testSuite-meta.xml", "exitCode": 1, "commandName": "Run", "stack": "INVALID_INPUT: Invalid ID or name: force-app/main/default/testSuites/vinay.testSuite-meta.xml Commented Jan 31, 2022 at 19:18
  • @Vinay The error message gives you a good idea of what's wrong. Like I mentioned in my answer, using the name of the testsuite rather than the path is an option. Based on your error, it is the only option. I'll edit my answer to make it clearer, but I suspect you wouldn't have run into the issue if you had read my answer all the way through. Commented Jan 31, 2022 at 19:23
  • Thanks @Derke F, Now it make sense. i'm able test that now. Commented Jan 31, 2022 at 19:36
  • Hi @Derek F, Is there any way to create "testSuite" using SFDX CLI instead to login in environment and create that ? Thanks in advance. Commented Jan 31, 2022 at 20:41

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.