# logic run test (Beta)

Invoke tests for Apex and Flows in an org.

:::note
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](https://www.salesforce.com/company/legal/agreements/).
:::

## Description for logic run test

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.

## Flags

| Flag Name (Long)      | Flag Name (Short) | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| --------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `--api-version`       | N/A               | **Type:** Value<br><br>Override the api version used for api requests made by this command                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `--class-names`       | `-n`              | **Type:** Value<br><br>Apex test class names to run; default is all classes.<br><br>If you select --class-names, you can't specify --suite-names or --tests.<br><br>For multiple classes, repeat the flag for each.<br><br>--class-names Class1 --class-names Class2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `--code-coverage`     | `-c`              | **Type:** Boolean<br><br>Retrieve code coverage results.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `--concise`           | N/A               | **Type:** Boolean<br><br>Display only failed test results; works with human-readable output only.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `--detailed-coverage` | `-v`              | **Type:** Boolean<br><br>Display detailed code coverage per test.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `--flags-dir`         | N/A               | **Type:** Value<br><br>Import flag values from a directory.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `--json`              | N/A               | **Type:** Boolean<br><br>Format output as json.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `--output-dir`        | `-d`              | **Type:** Value<br><br>Directory in which to store test run files.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `--result-format`     | `-r`              | **Type:** Value<br>**Valid Values:** `human`, `tap`, `junit`, `json`<br>**Default value:** `human`<br><br>Format of the test results.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `--suite-names`       | `-s`              | **Type:** Value<br><br>Apex test suite names to run.<br><br>If you select --suite-names, you can't specify --class-names or --tests.<br><br>For multiple suites, repeat the flag for each.<br><br>--suite-names Suite1 --suite-names Suite2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `--synchronous`       | `-y`              | **Type:** Boolean<br><br>Runs test methods from a single Apex class synchronously; if not specified, tests are run asynchronously.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `--target-org`        | `-o`              | **Type:** Value<br>**Required**<br><br>Username or alias of the target org. Not required if the `target-org` configuration variable is already set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `--test-category`     | N/A               | **Type:** Value<br>**Valid Values:** `Apex`, `Flow`<br><br>Category of tests to run, such as Apex or Flow.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `--test-level`        | `-l`              | **Type:** Value<br>**Valid Values:** `RunLocalTests`, `RunAllTestsInOrg`, `RunSpecifiedTests`<br><br>Level of tests to run; default is RunLocalTests.<br><br>Here's what the levels mean:<br><br><ul><li>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.</li><li>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.</li><li>RunAllTestsInOrg — All tests are run. The tests include all tests in your org.</li></ul> |
| `--tests`             | `-t`              | **Type:** Value<br><br>Comma-separated list of test names to run. Can include Apex test classes and Flow tests.<br><br>If you specify --tests, you can't specify --class-names or --suite-names<br><br>For multiple tests, repeat the flag for each.<br><br>--tests Test1 --tests Test2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `--wait`              | `-w`              | **Type:** Value<br><br>Sets the streaming client socket timeout in minutes; specify a longer wait time if timeouts occur frequently.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |

## Examples for logic run test

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

```shell
sf logic run test --tests MyApexClassTest,FlowTesting.Modify_Account_Desc.Modify_Account_Desc_TestAccountDescription
```

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

```shell
sf logic run test --test-level RunLocalTests --test-category Apex --test-category Flow --synchronous --target-org my-scratch
```

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

```shell
sf logic run test --class-names MyApexClassTest.methodA --class-names MyApexClassTest.methodB --suite-names MySuite
```

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

```shell
sf logic run test --result-format junit --output-dir test-results --synchronous --code-coverage
```
