Loading
Salesforce now sends email only from verified domains. Read More
Help Agent Performance DegradationRead More
Enhance Salesforce with Code
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Application Unit Tests

          Application Unit Tests

          Run Apex and automated flow unit tests on methods, classes, sets of classes, or your whole org.

          Required Editions

          Available in: Salesforce Classic (not available in all orgs) and Lightning Experience

          Available in: Enterprise, Performance, Unlimited, Developer, and Database.com Editions

          Managed Packages are not available in Database.com.

          See Supported Editions for Flow Builder and Licenses for Integrated Features

          User Permissions Needed
          To define, edit, delete, set security, and set version settings for Apex classes: Author Apex
          To run Apex tests: View Setup and Configuration
          To open, edit, or create a flow test in Flow Builder: Manage Flow
          To view test run details in Flow Builder: View All Data
          Note
          Note Only flow tests created with automated flow testing in Flow Builder are supported.

          You can run these groupings of Apex and flow unit tests.

          • Some or all methods in a specific class
          • Some or all methods in a set of classes
          • A predefined suite of classes, known as a test suite
          • All unit tests in your org

          Apex tests that are started from the Salesforce user interface run in parallel. Unless your test run includes only one class, and you didn’t select Always Run Asynchronously from the Developer Console’s Test menu, test runs started from the user interface are asynchronous. Apex test classes are placed in the Apex job queue for execution. The maximum number of test classes you can run per 24-hour period is the greater of 500 or 10 multiplied by the number of test classes in the org. For sandbox and Developer Edition organizations, this limit is the greater of 500 or 20 multiplied by the number of test classes in the org.

          Code Coverage by Unit Tests

          Before you can deploy your code or package it for the Salesforce AppExchange, the following must be true:

          • Unit tests must cover at least 75% of your Apex code, and all of those tests must complete successfully.
            • When deploying Apex to a production organization, each unit test in your organization namespace is executed by default.
            • Calls to System.debug are not counted as part of Apex code coverage.
            • Test methods and test classes are not counted as part of Apex code coverage.
            • While only 75% of your Apex code must be covered by tests, don’t focus on the percentage of code that is covered. Instead, make sure that every use case of your application is covered, including positive and negative cases, as well as bulk and single records. This approach ensures that 75% or more of your code is covered by unit tests.
          • Every trigger must have some test coverage.
          • All classes and triggers must compile successfully.

          If your test calls another class or causes a trigger to execute, that class or trigger is included in the code coverage calculations.

          After tests are executed, code coverage results are available in the Developer Console.

          To generate code coverage results, first run your tests using one of the following methods.

          • To run all tests from the Developer Console, select Test | Run All. Running a subset of tests doesn’t always update code coverage results properly, so running all your tests is the best way to see your code coverage.
          • To select and run tests from the Developer Console, see Create a Test Run.
          • To set up a reusable test suite from the Developer Console, see Manage Sets of Apex Test Classes with Test Suites.
          • To run all Apex tests from Setup, enter Apex in the Quick Find box, select Apex Classes, then click Run All Tests.
          • To run tests for an individual class from Setup, enter Application in the Quick Find box, then select Application Test Execution. Click Select Tests, select the classes containing the tests you want to run, and then click Run.

          After running tests, you can view code coverage results in the Developer Console. These results include the lines of code that are covered by tests for an individual class or trigger. See Checking Code Coverage.

           
          Loading
          Salesforce Help | Article