---
schema_version: "1"
id: 919bb15cfc4873a169e3c51d0a8ad09614fc2a09dfdc74a5b1d31c5da5bfea91
title: TestSetup Annotation
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_classes_annotation_testsetup.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_testsetup.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 317f89f74fc75adebbf8982b8ff66c60c1ba03e57c51fcc85b28d819a3f6bd90
description: Methods defined with the @TestSetup annotation are used for creating common test records that are available for all test methods in the class.
---
# TestSetup Annotation

Methods defined with the @TestSetup annotation are used for creating common test records that are available for all test methods in the class.

## Syntax

Test setup methods are defined in a test class, take no arguments, and return no value. The following is the syntax of a test setup method, where methodName is a placeholder value:

@TestSetup static void methodName() {

}

If a test class contains a test setup method, the testing framework executes the test setup method first, before any test method in the class. Records that are created in a test setup method are available to all test methods in the test class and are rolled back at the end of test class execution. If a test method changes those records, such as record field updates or record deletions, those changes are rolled back after each test method finishes execution. The next executing test method gets access to the original unmodified state of those records.

![Note](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/images/icon_note.png)

#### Note

You can have only one test setup method per test class.

Test setup methods are supported only with the default data isolation mode for a test class. If the test class or a test method has access to organization data by using the @IsTest(SeeAllData=true) annotation, test setup methods aren’t supported in this class. Because data isolation for tests is available for API versions 24.0 and later, test setup methods are also available for those versions only.

For more information, see [Using Test Setup Methods](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_testsetup_using.htm "Use test setup methods (methods that are annotated with @TestSetup) to create test records once and then access them in every test method in the test class. Test setup methods can be time-saving when you need to create reference or prerequisite data for all test methods, or a common set of records that all test methods operate on.").

- [← Previous](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_SuppressWarnings.htm "SuppressWarnings Annotation")
- [Next →](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_TearDown.htm "TearDown Annotation (Developer Preview)")