<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTestCase/setUp()",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTestCase(cm)setUp"
  },
  "title" : "setUp()"
}
-->

# setUp()

Provides an opportunity to customize initial state before a test case begins.

```
class func setUp()
```

## Discussion

The [`setUp()`](/documentation/XCTest/XCTestCase/setUp()) class method is called exactly once for a test case, before its first test method is called. Override this method to customize the initial state for all tests in the test case.

## See Also

[`setUp()`](/documentation/XCTest/XCTest/setUp())

Provides an opportunity to reset state before calling each test method in a test case.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)