xunit test patterns refactoring test code phần 9

Chúng ta có thể đạt được mục tiêu này bằng cách đi qua tất cả các đối số cho các phương pháp này một cách rõ ràng như các thông số (chứ không phải sử dụng các biến dụ) và bằng cách trả lại bất kỳ đối tượng mà các bài kiểm tra sẽ yêu cầu các giá trị trả lại là rõ ràng | Humble Object 8 SimpcHPDFRMergeEand-Split UnregisteredTVersion - http the transaction. As a consequence we can exercise the logic verify the outcome and then abort the transaction leaving no trace of our activity in the database. To implement Humble Transaction Controller we use an Extract Method Fowler refactoring to move all the logic we want to test out of the code that controls the transaction and into a separate method that knows nothing about transaction control and that can be called by the test. Because the caller controls the transaction the test can start commit if it so chooses and most commonly roll back the transaction. In this case the behavior not the dependencies causes us to bypass the Humble Object when we are testing the business logic. As a result we are more likely to be able to get away with a Poor Man s Humble Object. As for the Humble Object it contains no business logic. Thus the only behavior that needs to be tested is whether the Humble Object commits and rolls back the transaction properly based on the outcome of the methods it calls. We can write a test that replaces the testable component with a Test Stub page 529 that throws an exception and then verify that this activity results in a rollback of the transaction. If we are using a Poor Man s Humble Object the stub would be implemented as a Subclassed Test Double see Test-Specific Subclass on page 579 that overrides the real methods with methods that throw exceptions. Many of the major application server technologies support this pattern either directly or indirectly by taking transaction control away from the business objects that we write. If we are building our software without using a transaction control framework we may need to implement our own Humble Transaction Controller. See the Implementation Notes section for some ideas on how we can enforce the separation. Variation Humble Container Adapter Speaking of containers we often have to implement specific .

2    9    1    28-07-2021