@flxbl-io/sfp apextestsManage apex tests in a package or an org
@flxbl-io/sfp apextests trigger
@flxbl-io/sfp apextests triggerTriggers Apex unit tests in an org with support for multiple test levels, code coverage validation, and flexible output formats. This command is essential for validating your Salesforce code changes during development and CI/CD pipelines.
New in November 2024: Dashboard output format (
--outputformat dashboard) provides structured JSON optimized for metrics collection and reporting tools.
The command creates a .testresults directory with the following structure:
Runs all tests in your org except those from managed packages. This is the default and recommended for most development scenarios.
Runs all tests within specified package(s). Ideal for package-focused development and supports coverage validation.
Runs tests for all packages in a domain defined in your release config. Perfect for domain-driven development.
Runs specific test classes or methods. Useful for quick validation during development.
Validates that each Apex class meets the minimum coverage threshold:
Validates overall package coverage percentage:
The dashboard format provides structured data optimized for reporting tools and dashboards:
Dashboard JSON includes:
Test execution summary (passed, failed, skipped)
Code coverage details per class
Individual test case results with timing
Environment and metadata information
Increase wait time for long-running tests:
Some test classes require serial execution. Configure in your package descriptor:
Check which classes failed coverage:
See code:
USAGE
$ @flxbl-io/sfp apextests trigger -o <value> [--loglevel
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL] [--apiversion <value>] [-l
RunSpecifiedTests|RunApexTestSuite|RunLocalTests|RunAllTestsInOrg|RunAllTestsInPackage|RunAllTestsInDomain]
[-n <value>] [-r <value>] [-c] [--validatepackagecoverage] [--specifiedtests <value>]
[--apextestsuite <value>] [-p <value>] [-w <value>] [--outputformat raw|dashboard|both]
[--environment <value>] [--commitsha <value>] [--repourl <value>]
FLAGS
-c, --validateindividualclasscoverage Validate that individual classes have a coverage greater than the minimum
required percentage coverage, only available when test level is
RunAllTestsInPackage
-l, --testlevel=<option> [default: RunLocalTests] The test level of the test that need to be executed
when the code is to be deployed
<options: RunSpecifiedTests|RunApexTestSuite|RunLocalTests|RunAllTestsInOrg|
RunAllTestsInPackage|RunAllTestsInDomain>
-n, --package=<value> Name of the package(s) to run tests. Can be specified multiple times.
Required when test level is RunAllTestsInPackage
-o, --targetusername=<value> (required) Username or alias of the target org
-p, --coveragepercent=<value> [default: 75] Minimum required percentage coverage, when validating code
coverage
-r, --releaseconfig=<value> Path to release config file. Required when test level is RunAllTestsInDomain
-w, --waittime=<value> Wait time for command to finish in minutes. Use 0 or omit for indefinite wait
--apextestsuite=<value> comma-separated list of Apex test suite names to run
--apiversion=<value> Override the api version used for api requests made by this command
--commitsha=<value> Git commit SHA for tracking test execution in reports
--environment=<value> Environment name for dashboard format (defaults to target org alias)
--loglevel=<option> [default: info] logging level for this command invocation
<options: trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL>
--outputformat=<option> [default: raw] Output format for test results
<options: raw|dashboard|both>
--repourl=<value> Repository URL for linking test results
--specifiedtests=<value> comma-separated list of Apex test class names or IDs and, if applicable, test
methods to run
--validatepackagecoverage Validate that the package coverage is greater than the minimum required
percentage coverage, only available when test level is RunAllTestsInPackage
DESCRIPTION
Triggers Apex unit tests in an org with support for multiple test levels, code coverage validation, and flexible
output formats.
Test Levels:
β’ RunLocalTests - Runs all tests in your org that are not from managed packages (default)
β’ RunAllTestsInOrg - Runs all tests in your org, including managed packages
β’ RunAllTestsInPackage - Runs all tests in specified package(s)
β’ RunAllTestsInDomain - Runs all tests for packages in a release config domain
β’ RunSpecifiedTests - Runs specific test classes or methods
β’ RunApexTestSuite - Runs all tests in a test suite
Output Formats:
β’ raw - Standard Salesforce API output (default) - generates JUnit XML and JSON results
β’ dashboard - Structured JSON format optimized for dashboards and reporting tools (November 2024+)
β’ both - Generates both raw and dashboard formats (November 2024+)
The command automatically creates a .testresults directory with:
β’ Test run results in JSON format
β’ JUnit XML for CI/CD integration
β’ Code coverage data (when coverage validation is enabled)
β’ Dashboard-formatted JSON (when using dashboard or both output formats)
β’ Markdown summary report
β’ Symlinks to latest test results
EXAMPLES
# Run all local tests in an org
$ sfp apextests trigger -o scratchorg -l RunLocalTests
# Run tests for a specific package with individual class coverage validation
$ sfp apextests trigger -o scratchorg -l RunAllTestsInPackage -n my-package -c
# Run tests for multiple packages
$ sfp apextests trigger -o scratchorg -l RunAllTestsInPackage -n package1 -n package2
# Run tests for all packages in a domain (from release config)
$ sfp apextests trigger -o scratchorg -l RunAllTestsInDomain -r config/release-config.yaml
# Run specific test classes
$ sfp apextests trigger -o scratchorg -l RunSpecifiedTests --specifiedtests PaymentTest,InvoiceTest
# Run test suite
$ sfp apextests trigger -o scratchorg -l RunApexTestSuite --apextestsuite MySuite
# Run with package coverage validation (75% minimum)
$ sfp apextests trigger -o scratchorg -l RunAllTestsInPackage -n my-package --validatepackagecoverage -p 75
# Run with dashboard output format for reporting
$ sfp apextests trigger -o scratchorg -l RunLocalTests --outputformat dashboard --environment dev
# Run with both output formats in CI/CD
$ sfp apextests trigger -o scratchorg -l RunLocalTests \
--outputformat both \
--environment ci \
--commitsha $CI_COMMIT_SHA \
--repourl https://github.com/myorg/myrepo
# Get JSON output for parsing in scripts
$ sfp apextests trigger -o scratchorg -l RunLocalTests --outputformat dashboard --json
# Wait indefinitely for large test suites
$ sfp apextests trigger -o scratchorg -l RunAllTestsInPackage -n my-package -w 0
# Set specific wait time
$ sfp apextests trigger -o scratchorg -l RunAllTestsInPackage -n my-package -w 120.testresults/
βββ test-result-<testRunId>-junit.xml # JUnit XML format
βββ test-result-<testRunId>.json # Raw Salesforce test results
βββ test-result-<testRunId>-coverage.json # Code coverage data
βββ <testRunId>/ # Dashboard format directory
β βββ dashboard.json # Structured test results
β βββ testresults.md # Markdown summary
βββ latest.json # Symlink to latest dashboard resultsfp apextests trigger -o dev-org -l RunLocalTests# Single package
sfp apextests trigger -o dev-org -l RunAllTestsInPackage -n sales-core
# Multiple packages
sfp apextests trigger -o dev-org -l RunAllTestsInPackage -n sales-core -n sales-uisfp apextests trigger -o dev-org -l RunAllTestsInDomain -r config/release-config.yaml# Run specific test classes
sfp apextests trigger -o dev-org -l RunSpecifiedTests --specifiedtests AccountTest,ContactTest
# Run specific test methods
sfp apextests trigger -o dev-org -l RunSpecifiedTests --specifiedtests AccountTest.testCreate,ContactTest.testUpdatesfp apextests trigger -o dev-org -l RunAllTestsInPackage -n my-package -c -p 80sfp apextests trigger -o dev-org -l RunAllTestsInPackage -n my-package --validatepackagecoverage -p 75sfp apextests trigger -o dev-org -l RunLocalTests --outputformat dashboard --environment production- name: Run Apex Tests
run: |
sfp apextests trigger \
--targetusername ${{ secrets.ORG_ALIAS }} \
--testlevel RunLocalTests \
--outputformat both \
--environment ci \
--commitsha ${{ github.sha }} \
--repourl ${{ github.repository }} \
--json > test-results.json
- name: Upload Test Results
uses: actions/upload-artifact@v3
with:
name: apex-test-results
path: .testresults/# Capture output for parsing
RESULT=$(sfp apextests trigger -o dev-org -l RunLocalTests --outputformat dashboard --json)
# Extract test run ID
TEST_RUN_ID=$(echo $RESULT | jq -r '.result.testRunId')
# Extract summary
PASSED=$(echo $RESULT | jq -r '.result.summary.passedPackages')
FAILED=$(echo $RESULT | jq -r '.result.summary.failedPackages')sfp apextests trigger -o dev-org -l RunLocalTests -w 120{
"testSynchronous": true
}sfp apextests trigger -o dev-org -l RunAllTestsInPackage -n my-package -c --loglevel debug