Đang chuẩn bị liên kết để tải về tài liệu:
Java Extreme Programming Cookbook phần 5

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

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 WebResponse.getTableStartingWith method. Example 5-2. Simple table testing public void testPersonTable throws Exception WebConversation webConversation new WebConversation WebResponse response webConversation.getResponse http localhost 8080 news sampleTable.html get the HTML table with First Name as the text of its first non-blank cell WebTable table response.getTableStartingWith First Name assertEquals column count 2 table.getColumnCount assertEquals row count 3 table.getRowCount get the cell at row 2 column 0 TableCell cell table.getTableCell 2 0 assertEquals cell text Tanner cell.asText 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 webConversation.getResponse http localhost 8080 news sampleTable.html WebTable accountTable response.getTableWithID accountInfoTbl assertNotNull account table accountTable get the checking account number TableCell checkingCell accountTable.getTableCellWithID checkingAcctNbr assertEquals Checking account number 12345 checkingCell.asText 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 .

crossorigin="anonymous">
Đã 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.