Upload
lawrence-tucker
View
215
Download
0
Tags:
Embed Size (px)
Citation preview
Magnus Hä[email protected]@MagnusHarlin
What is testability?Repeatable - You should be able to expect the
outcome for known inputsEasy to writeEasy to understandFast
Value of automated testingReduce the time coding + debugging +
testingGives you better maintainabilityQuick feedback mechanismTests as documentation
Comparison
the ease of developing in one code base compared to another
Separation of ConcernsReadabilityLess complexityHigher cohesionLower coupling
Isolate the ugly stuff (infrastructure) Db-access Active Directory Web services Configuration files
Not isolated
InterfaceRefers to a set of named operations that can be
invoked by clients
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);
}}
public void ProcessOrderAgainstService(Order order){
IOrderRepository orderRepository = new OrderService();orderRepository.ProcessOrder(order);
}
public void ProcessOrder(Order order){
IOrderRepository orderRepository = new OrderRepository();orderRepository.ProcessOrder(order);
}
Dependency Injection (DI)
Instead of a class creating its own dependencies,
its dependencies are inserted into it.
Business LayerData Layer Interface
Data Layer
Service Layer
MockingUse mock object as placeholders for classes
that don’t yet existDon’t mock chatty interfacesFake objects with return and pre-canned
values
Small Tests Before Big TestsSmall focused test will tell you where
something is wrongFast and accurate feedback loopsBoth big (end to end) and small test are
important
The Gateway PatternEncapsulate access to external services by
encapsulating the implementation with interfaces
Object that encapsulates external system
Questions
The big picture - ConclusionTestable system will change your design. There are times when a design decision is
made only to enable testingTestability goes hand in hand with classical
definition of good design - high cohesion, low coupling and separation of concerns
Design for testability gives you maintainability