1 / 19

Design For Testability

Design For Testability. Magnus Härlin magnus.harlin@iptor.com @MagnusHarlin. What is testability?. Repeatable - You should be able to expect the outcome for known inputs Easy to write Easy to understand Fast. Value of automated testing. Reduce the time coding + debugging + testing

yered
Download Presentation

Design For Testability

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Design For Testability Magnus Härlin magnus.harlin@iptor.com @MagnusHarlin

  2. What is testability? Repeatable - You should be able to expect the outcome for known inputs Easy to write Easy to understand Fast

  3. Value of automated testing Reduce the time coding + debugging + testing Gives you better maintainability Quick feedback mechanism Tests as documentation

  4. Comparison the ease of developing in one code base compared to another

  5. Separation of Concerns Readability Less complexity Higher cohesion Lower coupling

  6. Isolate the ugly stuff (infrastructure)     Db-access     Active Directory     Web services     Configuration files

  7. Not isolated Service Layer Business Layer Data Layer

  8. Interface Refers to a set of named operations that can be invoked by clients

  9. publicclassOrderManager { public void ProcessOrder(Order order) { OrderRepository orderRepository = newOrderRepository(); orderRepository.ProcessOrder(order); } } publicclassOrderManager { public void ProcessOrder(Order order) { IOrderRepository orderRepository = newOrderRepository(); orderRepository.ProcessOrder(order); } }

  10. public void ProcessOrderAgainstService(Order order) { IOrderRepository orderRepository = newOrderService(); orderRepository.ProcessOrder(order); } public void ProcessOrder(Order order) { IOrderRepository orderRepository = newOrderRepository(); orderRepository.ProcessOrder(order); }

  11. Dependency Injection (DI) Instead of a class creating its own dependencies, its dependencies are inserted into it.

  12. Service Layer Business Layer Data Layer Interface Data Layer

  13. Mocking Use mock object as placeholders for classes that don’t yet exist Don’t mock chatty interfaces Fake objects with return and pre-canned values

  14. Small Tests Before Big Tests Small focused test will tell you where something is wrong Fast and accurate feedback loops Both big (end to end) and small test are important

  15. The Gateway Pattern Encapsulate access to external services by encapsulating the implementation with interfaces Object that encapsulates external system

  16. Questions

  17. The big picture - Conclusion Testable system will change your design.  There are times when a design decision is made only to enable testing Testability goes hand in hand with classical definition of good design - high cohesion, low coupling and separation of concerns Design for testability gives you maintainability

More Related