How to Run Apex tests in an org from VS Code Using SF CLI

We can Execute the apex test classes from vs code ide using salesforce cli. Also run specific test class or, specific test method or test suits with or without code coverage and human readable format. 

Run specified Apex test class in org 

we can run specified single apex test class from vs code console.
sf apex run test -n MyClassTest -r human

Run specified Apex test method in org

we can also run specified single test method from apex class.
sf apex run test -t "MyClassTest.testCoolFeature" -r human

Run specified Apex test suites in org 

Run test suit in an org.
sf apex run test -s "MyTestSuite" -c -v

Run all Apex tests and suites in org

Using following sf cli command to run all tests and suites in your org.
sf apex run test

Flags:

  • -n : Name of the test class
  • -r : Test results format, supported formats: human, tap, junit, json
  • -t : Tests  
  • -s : Test suite name
  • -c : If you want to get code coverage, it's boolean
  • -v : Detailed code coverage per test

Source:
https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_apex_commands_unified.htm#cli_reference_apex_run_test_unified

Labels:
Join the conversation