tailieunhanh - Extreme Programming in Perl PHẦN 8

Test-điều khiển thiết kế giúp chúng ta phát minh ra giao diện có thể kiểm chứng và có thể sử dụng. Trong nhiều cách, testability và khả năng sử dụng là một trong cùng một. Nếu bạn không thể viết một thử nghiệm cho một API, nó có thể sẽ khó sử dụng, và ngược lại. | message in the test mailbox. What we do know is that if we Delete all messages from one to Count the mailbox should be empty. The second half of this case group tests this behavior. The empty mailbox case is important to test too. By deleting all messages and trying to login we ll see how Mail POP3Client behaves in the this case. Yet another reason to delete all messages is to reset the mailbox to a known state so the next test run starts with a clean slate. This selfmaintaining property is important for tests that access persistent data. Rerun the entire test twice in a row and the second run should always be correct. The POP3 protocol doesn t remove messages when Delete is called. The messages are marked for deletion and the server deletes them on successful Close. Reset clears any deletion marks. We cross-validate the first Count result with the second to verify Reset does what it is supposed to do. Consistent APIs Ease Testing pop3 Mail POP3Client- new is pop3- State 39 DEAD 39 is pop3- Alive 39 39 is pop3- Host cfg- HOST cfg- HOST is pop3- Host cfg- HOST pop3- Connect is pop3- Alive 1 is pop3- State 39 AUTHORIZATION 39 is pop3- User cfg- USER cfg- USER is pop3- User cfg- USER is pop3- Pass cfg- PASSWORD cfg- PASSWORD is pop3- Pass cfg- PASSWORD is pop3- Login 0 is pop3- State 39 TRANSACTION 39 is pop3- Alive 1 is pop3- Close 1 is pop3- Alive 39 39 is pop3- Close 0 pop3 Mail POP3Client- new pop3- Connect Copyright 2004 Robert Nagler All rights reserved nagler@ 121 is pop3- Alive 39 39 is pop3- Login 0 is pop3- State 39 DEAD 39 This section not only tests the accessors but also documents the State and Alive transitions after calls to Connect and Login. There s a minor design issue to discuss. The accessor Pass does not match its corresponding named parameter PASSWORD like the Host and User do. The lack of uniformity makes using a map function for the accessor tests cumbersome so we didn t bother. Also the non-uniform return values between .