software design for testability
DESCRIPTION
TRANSCRIPT
R&D Dept.Switching DivisionTesting Team
Design for Testability
Prepared By:-
Amr Medhat-
13 - 4 - 2006-
Design for TestabilityDesign for Testability
Outline
Testability: what, why, how and when?
The Design Dilemma Testability Features Techniques for Developing Quality-
Oriented Software
Design for TestabilityDesign for Testability
Testability .. What? Testability = controllability & visibility
Controllability: the ability to apply inputs to s/w under test & place it in specified states
Visibility: the ability to observe states and outputs [what we see is what we test]
Design for TestabilityDesign for Testability
Testability .. Why?
Improve software quality
Ease the test process and more support for test automation
Cost reductionThe average software company spends 60-
80% of its development costs on supporting [Lidor Wyssocky]
Design for TestabilityDesign for Testability
Testability .. How?
Investing more time in design[A good design is a testable design]
Adding testability features
Using special techniques throughout the development process
Design for TestabilityDesign for Testability
Testability .. When?
From Day 1 From Day 1
Testers has to be engaged early in the product development cycle
The product has to be open for design changes to meet the testing requirements
Design for TestabilityDesign for Testability
The Design Dilemma
The time given for design.... ?!
Polymorphism
Inheritance
Encapsulation
Data Abstraction
scalability?
modularity?
reusability?
maintainability?
?reliability?
Using the perfect tools....But in the wrong way ... !!!
Design for TestabilityDesign for Testability
Design Weakness: How & Why
Symptoms of a bad design Rigidity Fragility Immobility Viscosity
Causes of a bad design Lack of Abstraction Violation of Encapsulation Interdependence {between Objects & Layers}
Design for TestabilityDesign for Testability
Abstraction & Interfaces Separate interface from its
implementation use overriding to support polymorphism When deriving a class,
inherit interfacenot implementation
Implementation is either Extended Or, Overridden PolymorphismPolymorphism
Design for TestabilityDesign for Testability
Encapsulation Data are Private, Methods are Public…,
& Implementation Details are Hidden Encapsulating the data and the
functions operating on this data.myThing[] things = thingManager.getThingList();
for (int i = 0; i < things.length; i++) {
myThing thing = things[i];
if (thing.getName().equals(thingName)) {
return thingManager.delete(thing); } }
return thingManager.deleteThingNamed(thingName);
Design for TestabilityDesign for Testability
Interdependence
The Acyclic Dependencies Principle (ADP)
3 ways of communication Invoke Method Superiority Relation Raise Trigger Inferiority Relation Message Passing Peer Relation
Dependencies must notnot form cyclescycles
Design for TestabilityDesign for Testability
Class Design Principles
The Single Responsibility Principle (SRP)
The Open-Closed Principle (OCP)
The Liskov Substitution Principle (LSP)SubclassesSubclasses should be substitutablesubstitutable for
their base classes
A module should be open for extensionopen for extension but closed for modificationclosed for modification
Each class has only oneonly one responsibility
Design for TestabilityDesign for Testability
OCP Example
Copy
ReadKeyboard
WritePrinter
WriteDisk
Copy
Reader Writer
KeyboardReader
PrinterWriter
DiskWriter
ReadKeyboard
WritePrinter
WriteDisk
Design for TestabilityDesign for Testability
LSP Exampleclass Bird { public: virtual void fly();};
class Parrot : public Bird { public: virtual void mimic();};
void PlayWithBird (Bird& abird) { abird.fly(); // OK if Parrot. // if bird happens to be Penguin...OOOPS!!}
class Penguin : public Bird { public: void fly() { error (“Penguins don’t fly!”); } };
Does not model: “Penguins can’t fly”
It models “Penguins may fly, but if they try it is error”
Run-time error if attempt to fly not desirable
Design for TestabilityDesign for Testability
Testability Features
Logging events & verbose mode support
Assertions {make assumptions explicit}
Test points (fault injection hooks) Scriptable installation process
Design for TestabilityDesign for Testability
Testability Features (cont.) Benefits of Adding Testability Features
Detecting internal errors before they propagate Knowing the source and place of the problem easily Ability to reproduce bugs many times
Notes Time stamps may be useful in logging Well describe and identifying the logged event Agree on a standard format of logging all over the
system [The use of a stand-alone Logger] Use variable levels of logging Throwing exceptions upon an assertions violation
may be useful rather than just logging it as a warning
Design for TestabilityDesign for Testability
Development Techniques
Defensive ProgrammingAssertions everywhere
Design by Contract Test-Driven Development Mock Objects
A generic unit testing framework that supports TDD better than test stubs
Design for TestabilityDesign for Testability
Design by Contract
Preconditionswhat must be true when a method is
invoked
Postconditionswhat must be true after a method
completes successfully.
Class invariantswhat must be true about each instance of a
class.
Design for TestabilityDesign for Testability
Test-Driven Development Write tests first, then write the minimal code
the makes this test pass Tests provide the required specification for the
developer {A part of the documentation} Provides rapid feedback for the developer Emphasizes fast, incremental development Functionality is added in very small chunks Ensures 100% thoroughly unit tested code
Design for TestabilityDesign for Testability
Summary Design BetterDesign Better
Use interfaces Don’t violate encapsulation Avoid interdependence and cycles Class single responsibility Class open for extension closed for modification Class substitution (parent is more general than its child)
Add Testability FeaturesAdd Testability Features Logging Assertions Fault injection hooks
Enhance the Development ProcessEnhance the Development Process Design by contract Test-driven development
Design for TestabilityDesign for Testability
References1. Bret Pettichord, “Design for Testability”2. Jeffery E. Payne, Roger T. Alexander, Charles D. Hutchinson,
“Design-for-Testability for Object-Oriented Software”3. Robert Martin, “OO Design Quality Metrics An Analysis of
Dependencies”4. Rahul Tyagi, “Two principles to help create robust, reusable
object-oriented design apps”5. Robert C. Martin, “Design Principles and Design Patterns”6. Matt Weisfeld, "Object-Oriented Thought Process", Second
Edition, Sams Publishing7. Wikipedia8. http://www.johndeacon.net/OOAandD/top25GoldenRules.asp9. http://www.artima.com/weblogs/viewpost.jsp?thread=13235810. http://labs.cs.utt.ro/labs/ip2/html11. http://www.mertner.com/confluence/display/MbUnit/Design+
Standards
R&D Dept.Switching DivisionTesting Team
Thank You Very Much