Sub topic 5
NoTestRun: skipping tests
This chapter assumes you can read basic Apex and the @IsTest annotation. It also assumes you know the difference between a sandbox and production, and that you have run sf commands against an org. Earlier chapters covered why Apex tests gate a deployment and how coverage is measured. Here we look at the first of the four test levels, the one that runs nothing.
What NoTestRun does
NoTestRun tells the deployment not to execute any Apex tests. The platform still validates and saves your metadata. It simply skips the test phase that would otherwise run before the changes are committed.
Skipping tests has three consequences:
- Deployment time drops, because the test phase is often the longest part of a deploy.
- Code coverage is not checked, so the 75% rule is not enforced for this deployment.
- A failing test cannot block the deployment, because no test runs.
The speed is the reason the level exists. In a development loop you may deploy dozens of times a day, and running the whole test suite each time would waste hours.
What NoTestRun does not skip
NoTestRun skips tests only. The platform still performs every other check:
- Apex classes and triggers must compile. A syntax error or a reference to a missing field fails the deployment.
- Metadata dependencies must resolve. A custom field that a layout references must exist in the org or in the package.
- Metadata type rules still apply, such as required attributes and valid API names.
So NoTestRun removes the runtime check that your code behaves correctly. It does not remove the compile-time check that your code is valid.
Where you can use it
NoTestRun is meant for development environments. In practice that means sandboxes, scratch orgs, Developer Edition orgs and trial orgs. It is also the default level for those orgs when you set none, which a later chapter covers in full.
Production is stricter. The rule depends on what the deployment contains:
| Deployment target | Contains Apex classes or triggers | Result with NoTestRun |
|---|---|---|
| Sandbox or scratch org | Yes or no | Accepted |
| Production | No (for example fields, layouts, permission sets) | Accepted |
| Production | Yes | Rejected |
Production protects itself this way because Apex code runs on behalf of every user in the org. The platform requires proof that new code works and that the org's coverage stays healthy before it accepts the change. Metadata with no executable Apex, such as a page layout, carries no such risk, so production lets it through without tests.
The command
The spine's example deploys to a sandbox and skips tests:
sf project deploy start --source-dir force-app --target-org my-sandbox --test-level NoTestRunEach part does one job:
--source-dir force-appselects the local folder of source-format metadata to deploy.--target-org my-sandboxnames an org alias that you have already authorized.--test-level NoTestRunsets the test level. The value is case-sensitive in spelling terms, so copy it exactly.
If the target is a sandbox, you can drop --test-level and get the same behavior from the default. Writing it explicitly is still useful in scripts. A pipeline file that says NoTestRun documents the intent, and it keeps working if someone points the script at a different org.
Why a skipped test is still a risk
A deployment that skips tests is fast, but you have learned less from it. Consider this pair of classes, the same ones the spine uses for the test levels that do run tests:
public with sharing class AccountService {
public static Integer countByIndustry(String industry) {
return [SELECT COUNT() FROM Account WHERE Industry = :industry];
}
}
@IsTest
private class AccountServiceTest {
@IsTest
static void countsMatchingAccounts() {
insert new Account(Name = 'Acme', Industry = 'Energy');
Test.startTest();
Integer result = AccountService.countByIndustry('Energy');
Test.stopTest();
Assert.areEqual(1, result, 'Expected one Energy account');
}
}Suppose you change the query in countByIndustry to filter on the wrong field, for example Type instead of Industry. The class still compiles. With NoTestRun, the sandbox deployment succeeds, and you learn nothing about the mistake. With any other level that includes AccountServiceTest, the assertion fails and the deployment reports it.
The same logic applies to coverage. NoTestRun reports success even if a class has zero coverage. The gap only appears later, when you deploy to production and the 75% rule applies. A habit of using NoTestRun everywhere defers all test failures to the most expensive moment.
Where it fits in a workflow
The diagram shows the usual position of NoTestRun. It is the inner development loop, and tests run at later stages.
Notice that tests still run before production. NoTestRun does not remove testing from the process. It moves testing out of the inner loop and into the stages where the cost is justified.
You can also run tests in a sandbox without deploying at all, using sf apex run test. That separates "push my changes" from "check my changes", so you pick when to pay for the test run.
Common errors and gotchas
Production rejects the deployment. If you pass --test-level NoTestRun to a production org and the package includes an Apex class or trigger, the deployment fails with an error about the test level. The fix is to use a level that runs tests, such as RunLocalTests. Changing the package to remove the Apex is rarely the right answer, because you would be dropping the code you meant to ship.
Assuming a successful deploy means passing tests. A green deployment under NoTestRun says nothing about test results or coverage. Do not report such a deployment as "tested".
Expecting a quick deploy afterward. Quick deploy reuses a prior validation that ran tests and passed. A validation run with NoTestRun has no test results to reuse, so it cannot support a quick deploy to production. A later chapter covers validation and quick deploy.
Hidden failures in metadata with runtime logic. Flows, validation rules and triggers that run during your own data setup can behave differently once real tests exercise them. Skipping tests means skipping the first moment those interactions are exercised together.
Different behavior between environments. If a script relies on the default, the same command can behave differently when the target org changes. A sandbox applies NoTestRun, while a production org with Apex in the package runs local tests. State the level explicitly when you want the behavior to be predictable.
When NoTestRun is a good choice
Use it when all of these hold:
- The target is a sandbox, scratch org or developer org.
- You are iterating quickly and will run tests separately before the change moves on.
- A broken deployment costs you nothing beyond a retry.
Avoid it for shared integration sandboxes that mirror production behavior, or any stage where a teammate would take your result as verified.
Check your understanding
Exercise
You run sf project deploy start --source-dir force-app --target-org my-prod --test-level NoTestRun. The package contains one Apex trigger and two custom fields. What happens, and what would you change?
Show answer
Production rejects the deployment, because the package contains Apex and NoTestRun is not accepted for production deployments that include Apex. Change the level to one that runs tests, such as RunLocalTests, or RunSpecifiedTests with the relevant test classes. If the package held only the custom fields, NoTestRun would be accepted.
Exercise
A developer deploys to a sandbox with NoTestRun and the deployment succeeds. A class in the package has no test class at all. Is the deployment's success evidence that the class meets the 75% coverage rule?
Show answer
No. NoTestRun runs no tests and does not enforce coverage, so the class's lack of coverage is invisible. The problem surfaces later, when a deployment to production runs tests and the coverage rule applies.
Exercise
Name two checks that still happen during a NoTestRun deployment.
Show answer
Any two of: Apex classes and triggers must compile, metadata dependencies must resolve, and metadata type rules (such as valid names and required attributes) are still enforced.