tailieunhanh - Code Leader Using People, Tools, and Processes to Build Successful Software phần 4

, thông báo thất bại thực tế đã được kiểm tra để xác định con đường thông qua mã của bạn gây ra sự thất bại. c kiểm tra để xác định con đường thông qua mã của bạn gây ra sự thất bại. Nếu kết quả vào thứ ba là không chính xác, kết quả có thể được (như đầu ra bởi NUnit): | Chapter 4 Done Is Done corresponding MyClassFixture test class. That MyClassFixture test class should only test the code in MyClass and nothing else. Furthermore MyClassFixture should exercise all of the code in MyClass. That sounds simple at first but it can be harder to achieve than you might think. To make sure that you are testing all of the code under test and nothing else you have to carefully manage your dependencies. This is where a mock object framework can come in extremely handy. MyClassFixture needs to test only the code that lives in MyClass and not code in other classes that MyClass might call. The very best way to assure that you achieve that level of test separation is to use dependency injection and an inversion of control container. By using those two technologies together you can eliminate almost all runtime dependency issues and easily substitute test versions of all your dependencies at test time. Dependency injection and inversion of control are complex topics in and of themselves that are outside the scope of this book but in summary dependency injection means loading dependencies dynamically at runtime using interfaces and runtime type creation which means you don t have compile-time dependencies except on the interfaces and an inversion of control system usually involves passing all of your dependencies to each object s constructor. By setting up constructors that take only interfaces as their dependencies an inversion of control system can insert itself at runtime and automatically create classes that implement those interfaces based on declarative configuration. It takes real discipline and quite a bit of work to implement these technologies well but if it can be done it is very easy to remove any and all dependency issues at test time by providing test or mock versions of your interfaces. Even if you don t go quite that far many mocking frameworks provide support for creating runtime mock versions of your interfaces at test time. That .

TỪ KHÓA LIÊN QUAN