software design for testability

22
R&D Dept. Switching Division Testing Team Design for Testability Prepared By: - Amr Medhat - 13 - 4 - 2006 -

Upload: amr0mt

Post on 27-Jan-2015

148 views

Category:

Documents


4 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Software Design for Testability

R&D Dept.Switching DivisionTesting Team

Design for Testability

Prepared By:-

Amr Medhat-

13 - 4 - 2006-

Page 2: Software Design for Testability

Design for TestabilityDesign for Testability

Outline

Testability: what, why, how and when?

The Design Dilemma Testability Features Techniques for Developing Quality-

Oriented Software

Page 3: Software Design for Testability

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]

Page 4: Software Design for Testability

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]

Page 5: Software Design for Testability

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

Page 6: Software Design for Testability

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

Page 7: Software Design for Testability

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 ... !!!

Page 8: Software Design for Testability

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}

Page 9: Software Design for Testability

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

Page 10: Software Design for Testability

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);

Page 11: Software Design for Testability

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

Page 12: Software Design for Testability

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

Page 13: Software Design for Testability

Design for TestabilityDesign for Testability

OCP Example

Copy

ReadKeyboard

WritePrinter

WriteDisk

Copy

Reader Writer

KeyboardReader

PrinterWriter

DiskWriter

ReadKeyboard

WritePrinter

WriteDisk

Page 14: Software Design for Testability

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

Page 15: Software Design for Testability

Design for TestabilityDesign for Testability

Testability Features

Logging events & verbose mode support

Assertions {make assumptions explicit}

Test points (fault injection hooks) Scriptable installation process

Page 16: Software Design for Testability

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

Page 17: Software Design for Testability

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

Page 18: Software Design for Testability

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.

Page 19: Software Design for Testability

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

Page 20: Software Design for Testability

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

Page 21: Software Design for Testability

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

Page 22: Software Design for Testability

R&D Dept.Switching DivisionTesting Team

Thank You Very Much