Presentation is loading. Please wait.

Presentation is loading. Please wait.

Magnus

Similar presentations


Presentation on theme: "Magnus"— Presentation transcript:

1 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

10 public class OrderManager { public void ProcessOrder(Order order) { OrderRepository orderRepository = new OrderRepository(); orderRepository.ProcessOrder(order); } public class OrderManager { public void ProcessOrder(Order order) { IOrderRepository orderRepository = new OrderRepository(); orderRepository.ProcessOrder(order); } }

11 public void ProcessOrderAgainstService(Order order) { IOrderRepository orderRepository = new OrderService(); orderRepository.ProcessOrder(order); } public void ProcessOrder(Order order) { IOrderRepository orderRepository = new OrderRepository(); orderRepository.ProcessOrder(order); }

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

13

14 Business Layer Data Layer Interface Data Layer Service Layer

15 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

16 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

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

18 Questions

19 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


Download ppt "Magnus"

Similar presentations


Ads by Google