TAILIEUCHUNG - Java Extreme Programming Cookbook phần 5

Vấn đề với mã này nằm trong thực tế assertXXX () là gần như chắc chắn thực hiện trước khi các chủ đề bắt đầu bởi someAsynchronousMethod () có một cơ hội để làm công việc của mình. Chúng tôi thực sự cần phải làm một cái gì đó như thế này: 1. Gọi một phương pháp không đồng bộ. 2. Chờ cho đến khi phương pháp này là hoàn tất. 3. | Example 5-2 demonstrates how you can test the content of the top table. In this example the table is located based on the text found within its first cell using the method. Example 5-2. Simple table testing public void testPersonTable throws Exception WebConversation webConversation new WebConversation WebResponse response http localhost 8080 news get the HTML table with First Name as the text of its first non-blank cell WebTable table First Name assertEquals column count 2 assertEquals row count 3 get the cell at row 2 column 0 TableCell cell 2 0 assertEquals cell text Tanner Once the WebTable object is located the test uses various methods on the WebTable class to obtain the number of rows and columns as well as to locate a TableCell at a particular position. While this approach is fine for simple tables it tends to be too fragile. People may redesign page layout frequently and this sort of test is sensitive to things like exact row and column positions. A better approach shown in Example 5-3 is to assign identifiers to critical portions of your tables. Example 5-3. Testing a table with identifiers public void testAccountTable throws Exception WebConversation webConversation new WebConversation WebResponse response http localhost 8080 news WebTable accountTable accountInfoTbl assertNotNull account table accountTable get the checking account number TableCell checkingCell checkingAcctNbr assertEquals Checking account number 12345 Now by locating identifiers you can rearrange your table layout as you see fit. Unless you change the identifiers your tests continue functioning. Example 5-4 shows the HTML for the table being tested here so you can see what the id tag looks .

TỪ KHÓA LIÊN QUAN
Đã 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.