Lập trình Wrox Professional Xcode 3 cho Mac OS part 71

Tạo một lớp học thử nghiệm đơn vị và thêm nguồn fi le của mình cho các mục tiêu thử nghiệm đơn vị. Thêm phương pháp thử nghiệm trước lớp. Đăng ký thử nghiệm với các khuôn khổ kiểm tra đơn vị. | 560 CHAPTER 20 UNIT TESTING CREATING A UNIT TEST Once you have your unit test target created and configured adding unit tests is simple. Here are the basic steps 1. Create a unit test class and add its source file to the unit test target. 2. Add test methods to the class. 3. Register the tests with the unit testing framework. Unit test class files can go anywhere in your project but I suggest at the very least creating a group for them named Tests or Unit Tests. In a larger project you might organize your unit test files in a folder or you might group them together with the code that they test. The choice is yours. Each class that you create defines a group of tests. Each test is defined by a test method added to the class. A class can contain as many different tests as you desire but must contain at least one. How you organize your tests is entirely up to you but good practices dictate that a test class should limit itself to testing some functional unit of your code. It could test a single class or a set of related functions in your application. Once defined your tests must be registered with the unit testing framework so that it knows what tests to run. For Objective-C tests this happens automatically. Objective-C test methods must adhere to a simple naming scheme basically they must all begin with the name test. Objective-C introspection is then used to locate and run all of the tests you defined. For C unit tests you add a declaration for each test you ve written. The exact requirements for each are described in the Objective-C Tests and C Test Registration sections respectively. Each test method should perform its test and return. Macros are provided for checking the expectations of each test and reporting failures. A test is successful if it completes all of its tests and returns normally. An example test is shown in Listing 20-2. LISTING 20-2 Sample C unit test Available for download on void SieveOfEratosthenesTests testPrimes Test a number of .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
44    85    4    08-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.