Sub topic 8
RunAllTestsInOrg: including managed package tests
This chapter assumes you know the @IsTest annotation, the difference between sandboxes and production, and basic sf CLI usage. It covers the fourth and broadest deployment test level, RunAllTestsInOrg.
What it runs
RunAllTestsInOrg runs every Apex test in the target org. That includes your own tests, tests from unlocked packages, and tests that belong to installed managed packages.
The difference from RunLocalTests is one category of tests. RunLocalTests skips tests from installed managed packages. RunAllTestsInOrg does not skip them.
| Level | Your org's tests | Managed package tests |
|---|---|---|
| RunLocalTests | Yes | No |
| RunAllTestsInOrg | Yes | Yes |
Setting it from the CLI
Pass the level with --test-level. No --tests flag is needed, because the level already selects every test.
sf project deploy start --source-dir force-app --target-org my-prod --test-level RunAllTestsInOrgYou can also use the level for a validation-only run, which is covered in a later chapter:
sf project deploy validate --source-dir force-app --target-org my-prod --test-level RunAllTestsInOrgWhen to use it
Use this level when you want evidence that a change does not break anything in the org, including code you do not own. Typical cases:
- A release that changes shared objects, fields, or validation rules that managed package code may depend on.
- A periodic full regression check in a sandbox before a major release.
- A check after installing or upgrading a package, to confirm your customizations still work with it.
Trade-offs and common errors
Running more tests takes longer. In an org with several large packages, a full run can take much longer than RunLocalTests. Plan for that in pipeline timeouts.
Managed package tests are written by the package vendor. You cannot edit them, and they may fail for reasons that have nothing to do with your change. Examples are tests that assume specific org settings or data. A failure in a managed test fails the deployment the same way a failure in your own test does. If that happens, look at the class name in the failure output. A namespace prefix on the class name shows that the test belongs to a package. Then decide whether your change caused the failure or whether it already existed. Running the same level against an unchanged sandbox gives you a baseline to compare against.
Do not choose this level just because it is the strictest one. For routine production releases, RunLocalTests already covers all the code you are responsible for. Add the managed tests when the risk justifies the extra time.
Exercise
A production deployment passes with RunLocalTests but fails with RunAllTestsInOrg. The failing class name starts with a package namespace. What does this suggest, and what is a sensible next step?
Show answer
The failing test belongs to an installed managed package, which RunLocalTests skips. Check whether the failure is caused by your change by running the same level against an unchanged sandbox for comparison. If it also fails there, the problem already existed, so contact the package vendor or use a level that fits your risk. If it passes there, review which of your changes the package code depends on.
Exercise
Which flag must you add to --test-level RunAllTestsInOrg to choose which tests run?
Show answer
None. This level always runs every test in the org. The --tests flag is used only with RunSpecifiedTests.