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‑version | N/A | Type: Value Override the api version used for api requests made by this command |
‑‑class‑names | ‑n | Type: 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 | ‑c | Type: Boolean Retrieve code coverage results. |
‑‑concise | N/A | Type: Boolean Display only failed test results; works with human-readable output only. |
‑‑detailed‑coverage | ‑v | Type: Boolean Display detailed code coverage per test. |
‑‑flags‑dir | N/A | Type: Value Import flag values from a directory. |
‑‑json | N/A | Type: Boolean Format output as json. |
‑‑output‑dir | ‑d | Type: Value Directory in which to store test run files. |
‑‑result‑format | ‑r | Type: Value Valid Values: human, tap, junit, jsonDefault value: humanFormat of the test results. |
‑‑suite‑names | ‑s | Type: 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 | ‑y | Type: Boolean Runs test methods from a single Apex class synchronously; if not specified, tests are run asynchronously. |
‑‑target‑org | ‑o | Type: Value Required Username or alias of the target org. Not required if the target-org configuration variable is already set. |
‑‑test‑category | N/A | Type: Value Valid Values: Apex, FlowCategory of tests to run, such as Apex or Flow. |
‑‑test‑level | ‑l | Type: Value Valid Values: RunLocalTests, RunAllTestsInOrg, RunSpecifiedTestsLevel of tests to run; default is RunLocalTests. Here’s what the levels mean:
|
‑‑tests | ‑t | Type: 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 | ‑w | Type: 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: