Create and run unit tests, performance tests, and UI tests for your Xcode project.
- Xcode 5.0+
The XCTest framework enables you to write unit tests for your Xcode projects that integrate seamlessly with the Xcode testing workflow, as described in Testing with Xcode.
Tests assert that certain conditions are satisfied during test execution, and record test failures (with optional messages) if those conditions are not satisfied. Tests can also measure the performance of blocks of code to check for performance regressions, and can interact with an application's UI to validate user interaction flows.
To add tests to your project, create a new subclass of
XCTest, and add one or more test methods to the test case, as shown in Listing 1. Test methods are instance methods that take no parameters, do not return a value, and have a name that begins with "
test". Each test method you add becomes an individual test in your Xcode project.
This example defines an
Table, with a single test method,
test. This test method creates a new instance of a class called
Table, and checks that its
column properties are both equal to
Asserting Test Conditions
You can check (or assert) conditions inside test methods to make sure that your code is behaving as expected. Use the
XCTAssert family of functions to check for boolean conditions, nil or non-nil values, expected values, and thrown errors.
For example, Listing 1 above uses the
XCTAssert function to assert that two integers have the same value.