An abstract base class for creating, managing, and executing tests.


class XCTest : NSObject


The XCTest class provides shared functionality used by XCTestCase and XCTestSuite for creating, managing, and executing tests. In most cases, you should subclass XCTestCase directly when defining tests in your project.


Test Properties

var name: String

The name of the test.

var testCaseCount: Int

The number of test cases in this test.

var testRun: XCTestRun?

The XCTestRun object that executed the test.

var testRunClass: AnyClass?

The XCTestRun subclass to instantiate when the test is run, to hold the test’s results.

Setup and Teardown

func setUp()

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

func tearDown()

Provides an opportunity to perform cleanup after each test method in a test case ends.

Running Tests

func perform(XCTestRun)

Executes a specific test.

func run()

Creates an instance of the class specified by testRunClass and passes it as a parameter to the perform(_:) method.


Inherits From

Conforms To

See Also

Test Cases and Test Methods

Defining Test Cases and Test Methods

Add test cases and test methods to a test target to confirm that your code behaves as expected.

class XCTestCase

The primary class for defining test cases, test methods, and performance tests.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software