xunit test patterns refactoring test code phần 4

Chúng tôi thiết lập các trận đấu thử nghiệm hoặc kiểm tra kết quả bằng cách đi qua một cánh cửa trở lại (chẳng hạn như truy cập cơ sở dữ liệu trực tiếp). Hành vi xác nhận (468): Chúng tôi nắm bắt các kết quả gián tiếp của hệ thống theo thử nghiệm (SUT) như chúng xảy ra và so sánh chúng với các hành vi mong đợi. | Simpo PDF Merge and Split Unregistered Version - http Chapter 16 Behavior Smells Behavior Smells Smells in This Chapter Assertion Erratic Fragile Frequent Manual Slow 223 SimpcHPDFRMergeỉ andSplit Unregistered Version - http Assertion Roulette Assertion Roulette It is hard to tell which of several assertions within the same test method caused a test failure. Symptoms A test fails. Upon examining the output of the Test Runner page 377 we cannot determine exactly which assertion failed. Impact When a test fails during an automated Integration Build SCM it may be hard to tell exactly which assertion failed. If the problem cannot be reproduced on a developer s machine as may be the case if the problem is caused by environmental issues or Resource Optimism see Erratic Test on page 228 fixing the problem may be difficult and time-consuming. Causes Cause Eager Test A single test verifies too much functionality. Symptoms A test exercises several methods of the SUT or calls the same method several times interspersed with fixture setup logic and assertions. public void testFlightMileage_asKm2 throws Exception set up fixture exercise constructor Flight newFlight new Flight validFlightNumber verify constructed object assertEquals validFlightNumber assertEquals assertNull set up mileage 1122 exercise mileage translator int actualKilometres verify results int expectedKilometres 1810 assertEquals expectedKilometres actualKilometres Simpo PDF Merge and Split Unregistered Version - http now try it with a canceled flight try fail Expected exception catch InvalidRequestException e assertEquals Cannot get cancelled flight mileage Assertion Roulette Another possible symptom is that the test automater wants to .