The apextests trigger command allows you to independently execute Apex tests in your Salesforce org. While the validate command automatically runs tests per package during validation, this command gives you direct control over test execution with support for multiple test levels, code coverage validation, and output formats.
Primary Testing Patterns
sfp follows a package-centric testing approach where tests are organized and executed at the package or domain level, rather than running all org tests together. This aligns with how the validate command works and provides better isolation and faster feedback.
# Test a specific package (primary pattern)sfpapexteststrigger-omy-org-lRunAllTestsInPackage-nmy-package# Test all packages in a domain (recommended for domain validation)sfpapexteststrigger-omy-org-lRunAllTestsInDomain-rconfig/release-config.yaml# Test multiple packages togethersfpapexteststrigger-omy-org-lRunAllTestsInPackage-npackage-a-npackage-b# Quick test during developmentsfpapexteststrigger-omy-org-lRunSpecifiedTests--specifiedtestsMyTest
Test Levels
RunAllTestsInPackage (Recommended)
Runs all tests within specified package(s). This is the primary testing pattern in sfp and matches how the validate command executes tests. Supports code coverage validation at both package and individual class levels.
This pattern matches how validate command executes tests - each package is tested independently with its own test classes. This provides:
Better test isolation and faster feedback
Package-level code coverage validation
Clear attribution of test failures to specific packages
Parallel test execution per package (when enabled)
RunAllTestsInDomain (Recommended for Domain Validation)
Runs tests for all packages defined in a domain from your release config. This is the recommended pattern for validating entire domains and matches how you would validate a domain for release.
This executes tests for each package in the domain sequentially, providing comprehensive domain validation. Use this when:
Validating changes across a domain before release
Testing related packages together as a unit
Performing end-to-end domain validation
RunSpecifiedTests
Runs specific test classes or methods. Useful for rapid iteration during active development.
Use during development for quick feedback cycles when working on specific features.
RunApexTestSuite
Runs all tests in a test suite defined in your org.
Useful for running pre-defined test groups or smoke test suites.
RunLocalTests
Runs all tests in your org except those from managed packages. This is the default test level in Salesforce but not the recommended pattern in sfp.
Note: While this is the Salesforce default, sfp recommends package-level or domain-level testing for better isolation and faster feedback. Use this only when you specifically need to run all org tests together, such as for compliance requirements or full org validation.
RunAllTestsInOrg
Runs all tests in your org, including managed packages. Rarely used due to long execution time.
Use only for complete org validation scenarios.
Code Coverage Validation
Individual Class Coverage
Validates that each Apex class in the package meets the minimum coverage threshold. Every class must meet or exceed the specified percentage.
Coverage threshold:
Default: 75%
Adjustable with -p flag
Applied per class, not as an average
Output includes:
List of all classes with their coverage percentages
Classes that meet the threshold
Classes that fail to meet the threshold
Overall package coverage percentage
Package Coverage
Validates that the overall package coverage meets the minimum threshold. The average coverage across all classes must meet or exceed the specified percentage.
Coverage calculation:
Aggregates coverage across all classes in package
Calculated as: (total covered lines / total lines) * 100
Only classes with Apex code count toward coverage
Coverage vs No Coverage
Running tests without coverage flags still executes tests but doesn't fetch or validate coverage data:
Note: Fetching coverage data adds time to test execution, so only use it when needed.
Output Formats
Note: The dashboard output format is a new feature introduced in the November 2025 release of sfp-pro.
Raw Format (Default)
Standard Salesforce API output with JUnit XML and JSON results. This is the default format.
Generates:
.testresults/test-result-<testRunId>.json - Raw Salesforce test results
.testresults/test-result-<testRunId>-junit.xml - JUnit XML format
.testresults/test-result-<testRunId>-coverage.json - Coverage data (if coverage enabled)
.testresults/testresults.md - Markdown summary
Dashboard Format
Available in: sfp-pro November 2024 release and later
Structured JSON format optimized for dashboards, metrics systems, and reporting tools. Unlike the raw Salesforce API output, the dashboard format provides enriched, pre-processed data that's ready for consumption by external systems.
Generates all raw format files plus:
.testresults/<testRunId>/dashboard.json - Structured test results
# 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.testUpdate