logic run test (Beta)

Invoke tests for Apex and Flows in an org.

This feature is a Beta Service. Customers may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at Agreements and Terms.

This command provides a single and unified way to run tests for multiple Salesforce features, such as Apex classes and Flows. Running the tests together with a single command ensures seamless interoperability between the features.

By default, the command executes asynchronously and returns a test run ID. Then use the “sf logic get test” command to retrieve the results. If you want to wait for the test run to complete and see the results in the command output, use the –synchronous flag.

To run specific tests, use the –tests flag and pass it the names of Apex and Flow tests. For Apex, simply specify the name of the Apex test class. For Flows, use the format “FlowTesting.<name-of-flow-test>”. To find the name of all the flow tests in your org, run this command and specify the Flow category, such as “sf logic run test –synchronous –test-category Flow –test-level RunAllTestsInOrg”. The command displays a table of all the flow tests it ran; see the “TEST NAME” column for the full name of all available flow tests in your org.

You can also run specific test methods, although if you run the tests synchronously, the methods must belong to a single Apex class or Flow test. To run all tests of a certain category, use –test-category and –test-level together. If neither of these flags is specified, all local tests for all categories are run by default. You can also use the –class-names and –suite-names flags to run Apex test classes or suites.

To see code coverage results, use the –code-coverage flag with –result-format. The output displays a high-level summary of the test run and the code coverage values for the tested classes or flows. If you specify human-readable result format, use the –detailed-coverage flag to see detailed coverage results for each test method run.

You must have the “View All Data” org system permission to use this command. The permission is disabled by default and can be enabled only by a system administrator.

Flag Name (Long)Flag Name (Short)Description
‑‑api‑versionN/AType: Value

Override the api version used for api requests made by this command
‑‑class‑names‑nType: Value

Apex test class names to run; default is all classes.

If you select –class-names, you can’t specify –suite-names or –tests.

For multiple classes, repeat the flag for each.

–class-names Class1 –class-names Class2
‑‑code‑coverage‑cType: Boolean

Retrieve code coverage results.
‑‑conciseN/AType: Boolean

Display only failed test results; works with human-readable output only.
‑‑detailed‑coverage‑vType: Boolean

Display detailed code coverage per test.
‑‑flags‑dirN/AType: Value

Import flag values from a directory.
‑‑jsonN/AType: Boolean

Format output as json.
‑‑output‑dir‑dType: Value

Directory in which to store test run files.
‑‑result‑format‑rType: Value
Valid Values: human, tap, junit, json
Default value: human

Format of the test results.
‑‑suite‑names‑sType: Value

Apex test suite names to run.

If you select –suite-names, you can’t specify –class-names or –tests.

For multiple suites, repeat the flag for each.

–suite-names Suite1 –suite-names Suite2
‑‑synchronous‑yType: Boolean

Runs test methods from a single Apex class synchronously; if not specified, tests are run asynchronously.
‑‑target‑org‑oType: Value
Required

Username or alias of the target org. Not required if the target-org configuration variable is already set.
‑‑test‑categoryN/AType: Value
Valid Values: Apex, Flow

Category of tests to run, such as Apex or Flow.
‑‑test‑level‑lType: Value
Valid Values: RunLocalTests, RunAllTestsInOrg, RunSpecifiedTests

Level of tests to run; default is RunLocalTests.

Here’s what the levels mean:

  • RunSpecifiedTests — Only the tests that you specify in the runTests option are run. Code coverage requirements differ from the default coverage requirements when using this test level. The executed tests must cover each class and trigger in the deployment package for a minimum of 75% code coverage. This coverage is computed for each class and triggers individually, and is different than the overall coverage percentage.
  • RunLocalTests — All local tests in your org, including tests that originate from no-namespaced unlocked packages, are run. The tests that originate from installed managed packages and namespaced unlocked packages aren’t run. This test level is the default for production deployments that include Apex classes or triggers.
  • RunAllTestsInOrg — All tests are run. The tests include all tests in your org.
‑‑tests‑tType: Value

Comma-separated list of test names to run. Can include Apex test classes and Flow tests.

If you specify –tests, you can’t specify –class-names or –suite-names

For multiple tests, repeat the flag for each.

–tests Test1 –tests Test2
‑‑wait‑wType: Value

Sets the streaming client socket timeout in minutes; specify a longer wait time if timeouts occur frequently.

Run a mix of specific Apex and Flow tests asynchronously in your default org:

Run all local Apex and Flow tests and wait for the results to complete; run the tests in the org with alias “my-scratch”:

Run two methods in an Apex test class and an Apex test suite:

Run all local tests for all categories (the default behavior), save the JUnit results to the “test-results” directory, and include code coverage results: