A plugin that generates a list of tests that your automated process should run, so you can save time by not running all tests in your Salesforce org and avoid specifying them manually.
Table of Contents
Simply install the plugin using sf
:
sf plugins install apextestlist
This tool identifies Apex tests using three annotations:
Classes can specify which tests should be run using a comment with the @Tests:
prefix. Multiple tests can be separated by commas, spaces, or both.
// @Tests: SampleTest, SuperSampleTest
public class Sample {
// ...
}
This means that SampleTest
and SuperSampleTest
should be executed when Sample.cls
is modified.
Test suites can be specified using the @TestSuites:
prefix. Multiple suites can be separated by commas or spaces.
// @TestSuites: SampleSuite SampleSuite2
public class Sample {
// ...
}
This tells the tool to include all tests contained in SampleSuite
and SampleSuite2
.
The tool also detects all Apex classes marked with the @isTest
annotation. Any class or method marked with this annotation is assumed to be a test.
@isTest
private class SampleTest {
// This test will be included automatically
}
To generate a test list, run the command in any Salesforce DX project:
sf apextests list --format sf
Example output:
--tests SampleTest SuperSampleTest Sample2Test SuperSample2Test
This command is useful in CI/CD pipelines, dynamically generating the test list for deployments:
sf project deploy start $(sf apextests list)
The final deployment command would look like:
sf project deploy start --tests SampleTest SuperSampleTest Sample2Test SuperSample2Test SampleTriggerTest
By default, this tool does not verify if the tests specified in @Tests:
or @TestSuites:
exist in the project. To enable warnings for missing tests, use:
sf apextests list --ignore-missing-tests
This will print warnings for missing tests and exclude them from the output.
USAGE
$ sf apextests list -f <value> -x <value> -s -d <value> [--json]
FLAGS
-f, --format=<value> Output format. Available options:
- `sf` (default): CLI-friendly test list
- `csv`: Comma-separated values
-x, --manifest=<value> Manifest XML file (package.xml) to filter test annotations.
-s, --ignore-missing-tests [default: false] Ignore test methods that are not found in any local package directories.
-d, --ignore-package-directory Ignore a package directory when looking for test annotations.
Should match how they are declared in "sfdx-project.json".
Can be declared multiple times.
GLOBAL FLAGS
--json Format output as JSON.
EXAMPLES
List all test annotations found in package directories in Salesforce CLI format:
$ sf apextests list --format sf
List all test annotations in CSV format:
$ sf apextests list --format csv
List test annotations only for Apex classes/triggers in a manifest file:
$ sf apextests list --format sf --manifest package.xml
List test annotations only if they exist in the package directories:
$ sf apextests list --format sf --ignore-missing-tests
Exclude annotations found in the "force-app" directory:
$ sf apextests list -d "force-app"
If you encounter any issues or would like to suggest features, please create an issue.
This project is licensed under the BSD-3 license. Please see the LICENSE file for details.