Skip to content

renatoliveira/apex-test-list

Folders and files

NameName
Last commit message
Last commit date
Feb 14, 2025
Sep 23, 2024
Sep 6, 2024
Sep 6, 2024
Jan 20, 2025
Dec 12, 2024
Feb 13, 2025
Feb 13, 2025
Sep 6, 2024
Sep 6, 2024
Sep 6, 2024
Sep 18, 2024
Sep 18, 2024
Sep 6, 2024
Sep 6, 2024
Sep 6, 2024
Sep 6, 2024
Sep 6, 2024
Sep 13, 2024
Feb 13, 2025
Sep 6, 2024
Mar 14, 2025
Sep 18, 2024
Feb 13, 2025
Sep 13, 2024
Mar 15, 2025

Repository files navigation

Apex Test List

NPM Downloads/week License

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

Install

Simply install the plugin using sf:

sf plugins install apextestlist

Usage

This tool identifies Apex tests using three annotations:

1. @Tests: (Custom Comment Annotation)

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.

2. @TestSuites: (Custom Comment Annotation)

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.

3. @isTest (Apex Annotation)

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
}

Running the Tool

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

Handling Missing Tests

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.

Command Reference

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"

Issues

If you encounter any issues or would like to suggest features, please create an issue.

License

This project is licensed under the BSD-3 license. Please see the LICENSE file for details.