Information Technology Reference
In-Depth Information
1. Use File New Project to create a new project.
Check the unit testing options before you save the project. This creates a standard project with extra test
build features that include a build bundle and a test class.
2. Develop your project, modifying the standard project classes and adding new classes in the usual
way.
3. For each feature you want to test, add test case code to the test class file.
4. Initialize Xcode's settings to make sure the test code runs as it should.
5. Optionally, you can use standard debugging tools to verify the test code.
6. Whenever you need to test the project, select the test build and build it.
If the test build fails, correct the bugs in the project code.
7. When the project is complete, build a release version in the usual way.
Because the test code exists in a separate bundle, it isn't linked into a standard release build.
Because unit testing is open-ended, the example described in the rest of this chapter illustrates how to create a
single simple test case for a single trivial class; it's a very basic math operation in a math framework. Although
the framework and the test code are trivial, you can easily expand this example to meet the needs of a real pro-
ject.
NOTE
This example illustrates how to create unit test for an iOS project. The unit testing process for iOS and OS X pro-
jects is similar enough to be considered identical.
NOTE
If your project uses Core Data, you can include it in the usual way. Core Data features and unit testing features
are unrelated. You can add either, neither, or both to a project.
Creating a new project that supports unit testing
For both Xcode and iOS projects, the unit testing option appears as a check box, as shown in Figure 17.1. For
this example, create a new Navigation-based project and check the box. Save the project as UnitTest.
CAUTION
Although you can add unit testing to an existing project, it's not a simple process. It's more efficient to include
unit testing when you create a new project. If you don't use the test features, they won't get in your way, but
they'll be ready if you need them.
FIGURE 17.1
Creating a new project that supports unit testing
Search WWH ::




Custom Search