xunit test patterns refactoring test code phần 3

Chúng tôi gọi một phương thức tiện ích để đánh giá liệu một kết quả mong đợi đã đạt được. Tự động Teardown (503): Chúng tôi theo dõi của tất cả các nguồn lực được tạo ra trong một bài kiểm tra và tự động hủy / miễn phí cho họ trong teardown. Cửa Thao tác (327): | 8 SimpcHPDFRMergesancTSplit Unregistered Version - http How Do We Control Indirect Inputs Testing with indirect inputs is a bit simpler than testing with indirect outputs because the techniques used to test outputs build on those used to test inputs. Let s delve into indirect inputs first. To test the SUT with indirect inputs we must be able to control th e DOC well enough to cause it to return every possible kind of return value. That implies the availability of a suitable control point. Examples of the kinds of indirect inputs we want to be able to induce via this control point include Return values of methods functions Values of updatable arguments Exceptions that could be thrown Often the test can interact with the DOC to set up how it will respond to requests. For example if a component provides access to data in a database then we can use Back Door Setup see Back Door Manipulation on page 327 to insert specific values into a database that cause the component to respond in the desired ways . no items found one item found many items found . See Figure . In this specific case we can use the database itself as a control point. Figure Using Back Door Manipulation to indirectly control and observe the SUT. When the SUT stores its state in another component we may be able to manipulate that state by having the test interact directly with the other component via a back door. In most cases however this approach is neither practical nor even possible. We might not be able to use the real component for the following reasons Simpo PDF Merge and Split Unregistered Version -fhttp The real component cannot be manipulated to produce the desired indirect input. Only a true software error within the real component would result in the desired input to the SUT. The real component could be manipulated to make the input occur but doing so would not be cost-effective. The real component could be manipulated to make the input occur but .