TAILIEUCHUNG - PHP in Action phần 5

Kiểm tra đóng một phần của một phần điển hình của mã khách hàng. Bằng cách viết các thử nghiệm đầu tiên, chúng tôi nhận được để chơi với giao diện của lớp của chúng tôi một chút trước khi chúng tôi cam kết với nó. Trong thực tế, chúng tôi nhận được để thử nó ra đầu tiên trong các thử nghiệm. | The test plays the part of a typical piece of client code. By writing the test first we get to play with the interface of our class a little before we commit to it. In effect we get to try it out first in the test. We already have an empty test class called TestOfMysqlTransaction. Each individual test will be implemented as a method in the test class. Here is our first real test require_once . class TestOfMysqlTransaction extends UnitTestCase function testCanReadSimpleSelect transaction new MysqlTransaction result transaction- select select 1 as one row result- next this- assertEqual row one 1 O o SimpleTest does some magic here. When the test case executes it searches itself for all methods that start with test and runs them. If the method starts with any other name it will be skipped. We ll make use of this later but for now just remember to put test at the beginning of each method you want to run. Now we start pretending that the feature has been implemented as outlined in figure . Select sounds like a good name for an SQL select method. We pretend that the transaction class has a select method that is able to run an SQL SELECT. We also pretend that the results of the select call will come back as an iterator see section . Each call to next on the iterator will give us a row as a PHP array . Here we only expect to fetch one row so the usual iterator loop is absent. The assertEqual method is a SimpleTest assertion one of quite a few available. If the two parameters do not match up a failure message will be dispatched to the test reporter and we will get a big red bar. Figure is a simplified class diagram of the test setup. The MysqlTransaction and MysqlResult classes are in gray because they don t exist yet. They are implied by the code in the test method. The UnitTestCase class is part of the SimpleTest framework. Only one method of this class is shown although it has many others. When we run this test case we don t get to see the red

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.