SlideShare a Scribd company logo
1 of 87
Download to read offline
Giovanni Asproni
email: gasproni@asprotunity.com
twitter: @gasproni
linkedin: http://www.linkedin.com/in/gasproni
Design For Testability
What, Why, How
1
/dev/winter 2016 Cambridge
“...is the degree to which a software artifact (i.e. a
software system, software module, requirements- or
design document) supports testing in a given test
context. If the testability of the software artifact is
high, then finding faults in the system (if it has any) by
means of testing is easier.”
Software Testability
2
http://en.wikipedia.org/wiki/Software_testability
Why?
• Testability improves other qualities of the system, as
well as delivery time and cost
• Testability and system design depend on each other
3
Qualities
• Maintainability
• Evolvability
• Use-it-again-ility
• I refuse to call it“reusability”
• Supportability
• Diagnosability
• Delivery time
• Cost
4
Testability Depends On Design (And Vice Versa)
5
“To be tested a system has
to be designed to be
tested”
Design for Test (aka "Design for Testability" or "DFT") is a
name for design techniques that add certain testability
features to a microelectronic hardware product design. The
premise of the added features is that they make it easier to
develop and apply manufacturing tests for the designed
hardware. The purpose of manufacturing tests is to
validate that the product hardware contains no defects
that could, otherwise, adversely affect the product’s
correct functioning.
6
Design For Testability
http://en.wikipedia.org/wiki/Design_for_testing
Examples of Software Testability Features
• Dependency injection (technique not frameworks!)
• Configuration parameters
• There are more…
7
“All architecture is design but
not all design is architecture”
Grady Booch
Design And Architecture
8
http://handbookofsoftwarearchitecture.com/?p=63
By Grady_Booch,_CHM_2011_2.jpg: vonguard
from Oakland, Nmibia derivative work: YMS
[CC BY-SA 2.0 (http://creativecommons.org/
licenses/by-sa/2.0)], via Wikimedia Commons
Every software-intensive system has an architecture. In
some cases that architecture is intentional, while in
others it is accidental. Most of the time it is both, born of
the consequences of a myriad of design decisions made
by its architects and its developers over the lifetime of a
system, from its inception through its evolution. In that
sense, the architecture of a system is the naming of the
most significant design decisions that shape a system,
where we measure significant by cost of change and by
impact upon use.
Design And Architecture
9
http://handbookofsoftwarearchitecture.com/?p=63
Architecture Is For (1/2)
• Modelling, and reasoning about, important
aspects of the system
• Quality attributes: scalability, performance,
latency, testability, etc., often, cannot (easily) be
retrofitted
10
Architecture Is For (2/2)
• Recording and communicating decisions
• Guiding lower level design and implementation
decisions
• E.g., avoid“TDDing”the system in the wrong
direction
• Splitting work among teams (Conway’s Law)
11
Organizations which design
systems are constrained to
produce designs which are
copies of the communication
structures of these organizations.
Conway’s Law
12
http://www.melconway.com/Home/Committees_Paper.html
Conway’s Law
14
Testing shows the presence,
not the absence of bugs.
Edsger Dijkstra
"Edsger Wybe Dijkstra" by Hamilton Richards - manuscripts of Edsger W. Dijkstra,
University Texas at Austin. Licensed under CC BY-SA 3.0 via Wikimedia Commons -
http://commons.wikimedia.org/wiki/File:Edsger_Wybe_Dijkstra.jpg#/media/
File:Edsger_Wybe_Dijkstra.jpg
15
In theory there is no difference between
theory and practice. But, in practice, there
is.
16
“More than the act of testing, the act of
designing tests is one of the best bug
preventers known. The thinking that
must be done to create a useful test can
discover and eliminate bugs before they
are coded - indeed, test-design thinking
can discover and eliminate bugs at every
stage in the creation of software, from
conception to specification, to design,
coding and the rest.”
Boris Beizer
Well Chosen Tests
• Give us confidence changes don’t break existing
functionality
• Scale much better than formal methods and
formal inspections
• And support refactoring activities more
efficiently
• Most tests can be automated
17
Diagnosability
18
Diagnose: identify the nature of (an illness
or other problem) by examination of the
symptoms
Testable software is more diagnosable
Cost Of Software
• costtotal = costdevelop + costmaintain
• costmaintain = costunderstand + costchange + costtest + costdeploy
• The above costs are related with each other
19
Cost Of Maintenance
• Usually costmaintain/costtotal ~ 60%
• It is important to write maintainable software
20
“Frequently Forgotten Fundamental Facts about Software Engineering”Robert Glass, IEEE Software, May/June 2001,
http://www.eng.auburn.edu/~hendrix/comp6710/readings/Forgotten_Fundamentals_IEEE_Software_May_2001.pdf
As of 2011, the average cost per function point in the United States
is about $1,000 to build software applications and another $1,000
to maintain and support them for five years: $2,000 per function
point in total. For projects that use effective combinations of
defect prevention and defect removal activities and achieve high
quality levels, average development costs are only about $700 per
function point and maintenance, and support costs drop to about
$500 per function point: $1,200 per function point in total.
21
How Quality Affects Costs
From“The Economics of Software Quality”,
Capers Jones and Olivier Bonsignour
22
How Quality Affects Delivery Time
% of defects removed
Developmenttime
Most organisations are
somewhere around this point
Fastest schedule
~95 100
Source Steve McConnell: http://www.stevemcconnell.com/articles/art04.htm
23
“Quality is an accelerator”
John Clifford, Construx Software
How
24
Testability Measures
25
• Observability: how easy it is to infer internal states
from external outputs
• Controllability: how easy it is to set some internal
states of the system using external inputs
Seams
26
Seam: a seam is a place where you
can alter behaviour in your
program without editing it in that
place.
Enabling point: every seam has an
enabling point, a place where you
can make a decision to use one or
another.
Some Seam Types
27
• Object seams
• Link seams
• Preprocessing seams
• Test hooks
Example: object seam
28
29
public class EventServer implements Runnable {



...


private EventProducer eventProducer;

public EventServer(EventProducer eventProducer) {

this.eventProducer = eventProducer;

...

}



@Override

public void run() {

...

while (isRunning()) {

try {
...

Event event = eventProducer.next();

...

} catch (Throwable e) {

...

}

}

}

...

}
Seam
Enabling point
Example: link seam
30
31
public class EventServer implements Runnable {



...


private EventProducer eventProducer;

public EventServer() {

this.eventProducer = new SpecialEventProducer();

...

}



@Override

public void run() {

...

while (isRunning()) {

try {
...

Event event = eventProducer.next();

...

} catch (Throwable e) {

...

}

}

}

...

}
Seam
Defined in a different jar
Example: test hook
32
A test hook is code used to configure the system to
behave differently during testing.
Test Hooks
33
public class AClass {

...

public void method() {

...
// Initialise testing using
// some external property
boolean testing = ...

if (testing) {
// do something
}
else {
// do something else
}
}

...

}
34
Hook
35
Using Seams In Tests
36
@Test

public void generatesProxyCorrectly() {



final int value = 10;

final String expectedMethodName =
ServiceInterface.class.getMethods()[0].getName();

final Object[] args = {value};



serviceCaller = context.mock(ServiceCaller.class);

proxyMaker = new ServiceProxyMaker(serviceCaller);



context.checking(new Expectations() {{

oneOf(serviceCaller).call(args, expectedMethodName,
serviceAddress, Void.TYPE);

will(returnValue(null));

}});



ServiceInterface generatedProxy =
proxyMaker.make(serviceAddress,
ServiceInterface.class).service();

generatedProxy.call(value);

context.assertIsSatisfied();

}
public class AClass {

...

public void method() {

...
// Initialise testing using
// some external property
boolean testing = ...

if (testing) {
// do something
}
else {
// do something else
}
}

...

}
37
Hook
38
public class AClassTest {

…
@Test

public void methodDoesSomethin() {
// Set testing mode to true
…
// Set some other test context
…
AClass subject = new ACLass(…)

subject.method()
// Assert something
…
}

...

}
Principle: Keep Test Logic Out of Production Code
39
“Testing is about verifying the behavior of a system. If
the system behaves differently when under test, then
how can we be certain that the production code
actually works? Even worse, the test hooks could
cause the software to fail in production!”
Test hooks violate this principle.
They must be used only in
special situations, e.g., a
stepping stone in making
legacy code testable.
Test Doubles
• Sometimes we need to test classes that interact with other objects which are difficult to control
• The real object has nondeterministic behaviour (e.g., random number generator)
• The real object is difficult to set up (e.g., requiring a certain file system, database, or network
environment)
• The real object has behaviour that is hard to trigger (e.g., a network error)
• The real object is slow
• The real object has (or is) a user interface
• The test needs to ask the real object about how it was used (e.g., confirm that a callback
function was actually called)
• The real object does not yet exist (e.g., interfacing with other teams or new hardware
systems)
40
Test Doubles
• Dummies
• Stubs
• Spies
• Fakes
• Mocks
41
Dummies
• Dummy objects are passed around but never
actually used
• E.g., a mandatory argument in a constructor never
used during a specific test
42
Stubs
• Stubs provide canned answers to calls made during
the test
43
Spies
• Spies are stubs that also record some information
based on how they were called. (e.g., the number of
times a method has been called)
44
45
public class OrderStateTest {
private static String TALISKER = "Talisker";
private WarehouseStub warehouse = new WarehouseStub();
@Test
public void orderIsFilledIfEnoughInWarehouse() {
Order order = new Order(TALISKER, 50);
order.fill(warehouse);
assertTrue(order.isFilled())
assertTrue(warehouse.removeCalled);
}
@Test
public void orderDoesNotRemoveIfNotEnough() {
Order order = new Order(TALISKER, 51);
order.fill(warehouse);
assertFalse(order.isFilled());
assertFalse(warehouse.removeCalled);
}
}
Adapted from: http://martinfowler.com/articles/mocksArentStubs.html
public class WarehouseStub implements Warehouse {
public boolean removeCalled = false;
public void hasInventory(String brand, int amount) {
return “Talisker”.equals(brand) && amount <= 50
}
public void remove(String brand, int amount) {
removeCalled = true;
}
…..
}
Fakes
• Fake objects actually have working
implementations, but take some shortcuts which
make them not suitable for production (e.g., an in
memory database)
46
47
public class OrderStateTest {
private static String TALISKER = "Talisker";
private Warehouse warehouse = new WarehouseFake();
@Test
public void orderIsFilledIfEnoughInWarehouse() {
Order order = new Order(TALISKER, 50);
order.fill(warehouse);
assertTrue(order.isFilled())
}
@Test
public void orderDoesNotRemoveIfNotEnough() {
Order order = new Order(TALISKER, 51);
order.fill(warehouse);
assertFalse(order.isFilled());
}
}
Adapted from: http://martinfowler.com/articles/mocksArentStubs.html
public class WarehouseFake implements Warehouse {
private HashMap<String, Integer> inventoryByBrand;
public WarehouseFake() {
inventoryByBrand =
new HashMap<>(){{put(“Talisker”, 50);}}
}
public void hasInventory(String brand, int required) {
available = inventoryByBrand.get(brand)
return available != null && required <= available;
}
public void remove(String brand, int amount) {
available = inventoryByBrand.get(brand)
if (available == null || amount > available) {
// Manage the error…
}
else {
inventoryByBrand.put(brand, available - amount);
}
}
…..
}
Mocks
• Mocks are objects pre-programmed with
expectations which form a specification of the calls
they are expected to receive
48
49
@Test

public void generatesProxyCorrectly() {



final int value = 10;

final String expectedMethodName =
ServiceInterface.class.getMethods()[0].getName();

final Object[] args = {value};



serviceCaller = context.mock(ServiceCaller.class);

proxyMaker = new ServiceProxyMaker(serviceCaller);



context.checking(new Expectations() {{

oneOf(serviceCaller).call(args, expectedMethodName,
serviceAddress, Void.TYPE);

will(returnValue(null));

}});



ServiceInterface generatedProxy =
proxyMaker.make(serviceAddress,
ServiceInterface.class).service();

generatedProxy.call(value);

context.assertIsSatisfied();

}
Mocks Aren’t Stubs
• Mocks are meant for testing behaviour
• Stubs and all other doubles are generally used for
testing state
• Classic TDD vs Mockist TDD (Classic school vs
London School of TDD)
50
http://martinfowler.com/articles/mocksArentStubs.html
APIs
• APIs for testing
• To query / change the state of the system
• To query / change the configuration of the system
• Notifications
• Logs
• They often become support APIs
51
Some Examples
• Time providers
• Notifications of asynchronous events
• Timers to check performance parameters
• Etc.
52
53
System
Test System
Entry points for standard users
Entry points for testing
A big part of designing a software system for testability is
about deciding where to put the seams and their
enabling points, and to create the necessary APIs for
testing
54
...But There Is More
• Ease of building the system
• Deployability
• Configurability
55
Deployability
• How reliably and easily can the system be deployed in
a particular environment?
• Does it require some special hardware configuration?
• Does it require some special OS configuration?
• Does it require a special directory structure?
• Etc.
56
Configurability
• How easily can paths, dbs, and other external resources be
configured? E.g.:
• Are external resources hardcoded?
• Are paths fixed?
• Can resources be configured at compile time or runtime?
• Too few or too many (or the wrong) options could be a
problem
57
Tests And Runtimes
• Tests and system (partially) in same runtime
• Allows the use of dependency injection at the
language level
• Tests and system in separate runtimes
• Dependencies are setup via configuration
• May rely more on special APIs for testing
58
59
From:“Growing Object Oriented Software Guided By Tests”
60
Same Runtime: Manage Global State Carefully
• Global application state should not spill over
• Frameworks must play nicely
• Avoid singletons and global variables
Same Or Separate Runtimes?
• Same runtimes
• More fine grained functional testing
• Easier TDD at all levels
• Separate runtimes
• Better for testing qualities (aka“non-
functionals”)
• Proper full system testing
61
62
Test First at all levels makes it easier to design a
system for testability
63
But you will probably need also some
upfront design
Design Approaches
• Big upfront design
• No upfront design
• Rough upfront design
64
Design Approaches (A Different
Perspective)
• Architecture-indifferent
design
• Architecture-focused design
• Architecture hoisting
65
Big Upfront Design
“BDUF design for testability is hard
because it is difficult to know what the
tests will need in the way of control
points and observation points on the
SUT. We can easily build software that
is difficult to test. We can also spend a
lot of time designing in testability
mechanisms that are either insufficient
or unnecessary. Either way, we will
have spent a lot of effort with nothing
to show for it.”
From:“xUnit Test Patterns”
No Upfront Design
• Works if the design“emerges”by coding
and refactoring
• Can be quite effective in creating a
testable system
• Requires a higher level of expertise
• Challenging for teams bigger than 3-4
people
• Doesn’t work for large systems
Rough Upfront Design
• Helps the team to keep the big picture in mind
• Pull in the same direction
• E.g., helps in choosing the right refactoring paths
• Useful to hoist important qualities
• Design changes and evolves as necessary
Architectural Drivers
• Qualities (aka, non-functional requirements, or ilities)
• Scalability
• Security
• Performance
• Usability
• Etc.
69
70
“All quality requirements
should be quantified.”
Tom Gilb
Start Small!
71
“A complex system that
works is invariably found to
have evolved from a simple
system that worked”
Travel Light
• No speculative design
• Remove“reusable”and“flexible”from your
dictionary!
72
Travel Light: Beware Of
Frameworks
73
• Can be very useful...
• ...but they can impair testability (among other
things)
A Walking Skeleton is a tiny implementation of
the system that performs a small end-to-end
function. It need not use the final architecture,
but it should link together the main
architectural components. The architecture
and the functionality can then evolve in
parallel.
74
Walking Skeleton
From: http://alistair.cockburn.us/Walking+skeleton
75
Walking Skeleton
Database
Client
GUI Domain layer Server
Walking skeleton
Risk Based Testing
• Least testing
• Low likelihood of failure, low consequences of failure
• Moderate testing
• Low likelihood of failure, high consequences of failure
• High likelihood of failure, low consequences of failure
• Most testing
• High likelihood of failure, High consequences of
failure
76
What Kind Of Tests?
77
• Manual Tests?
• System Tests?
• Component Tests?
• Unit Tests?
78
Tests are mainly for maintainability
and evolution.
Tests Need To
• Be reasonably simple to create
• Or people will not create enough of them, or, perhaps, create just
some easy, but not necessarily high value, ones
• Provide feedback at the right granularity level (observability and
controllability)
• Running an entire distributed system to check the implementation
of a single class or method is inconvenient, to say the least
• Easy and fast to run
• Or they won’t be executed as often as they should be (if at all)
79
http://asprotunity.com/blog/system-tests-can-kill-your-project/
80
@Test

public void generatesProxyCorrectly() {



final int value = 10;

final String expectedMethodName =
ServiceInterface.class.getMethods()[0].getName();

final Object[] args = {value};



serviceCaller = context.mock(ServiceCaller.class);

proxyMaker = new ServiceProxyMaker(serviceCaller);



context.checking(new Expectations() {{

oneOf(serviceCaller).call(args, expectedMethodName,
serviceAddress, Void.TYPE);

will(returnValue(null));

}});



ServiceInterface generatedProxy =
proxyMaker.make(serviceAddress,
ServiceInterface.class).service();

generatedProxy.call(value);

context.assertIsSatisfied();

}
81
System
Test System
Entry points for standard users
Entry points for testing
• Can be quite complicated to setup and run, especially for distributed systems
• Can be very slow, making the feedback loop quite long
• May be very difficult or even impossible to run on a developer’s machine
• Don’t scale well compared to other kinds of automated tests
• Are unhelpful in pinpointing the hiding places of bugs found in production
• Their coarse-grained nature makes them unsuitable for checking that a single
component, class, function, or method has been implemented correctly.
82
System Tests (Limitations)
Can be very difficult to use with
distributed teams (especially in large
projects)
System Tests (Limitations)
83
Conway’s Law
Concluding Remarks
• Implications On Design
• Added complexity on some dimensions
• But added simplicity in others
• More stuff to take care of
• Tests need to be maintained
• ...But it’s still cheaper than running the application
manually to smoke test changes...
85
Take aways
• Testability improves other qualities of the system, as
well as delivery time and cost
• Testability and system design depend on each other
• Test First at all levels helps
86
87
Books
ptg6985396
From the Library of Giovanni Asproni

More Related Content

What's hot

01 software test engineering (manual testing)
01 software test engineering (manual testing)01 software test engineering (manual testing)
01 software test engineering (manual testing)Siddireddy Balu
 
White boxvsblackbox
White boxvsblackboxWhite boxvsblackbox
White boxvsblackboxsanerjjd
 
A survey of software testing
A survey of software testingA survey of software testing
A survey of software testingTao He
 
Testing artifacts test cases
Testing artifacts   test casesTesting artifacts   test cases
Testing artifacts test casesPetro Chernii
 
Model-Based Testing: Theory and Practice. Keynote @ MoTiP (ISSRE) 2012.
Model-Based Testing: Theory and Practice. Keynote @ MoTiP (ISSRE) 2012.Model-Based Testing: Theory and Practice. Keynote @ MoTiP (ISSRE) 2012.
Model-Based Testing: Theory and Practice. Keynote @ MoTiP (ISSRE) 2012.Wolfgang Grieskamp
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)David Ehringer
 
Software testing: an introduction - 2017
Software testing: an introduction - 2017Software testing: an introduction - 2017
Software testing: an introduction - 2017XavierDevroey
 
07 Outsource To India Independent Testing
07 Outsource To India Independent Testing07 Outsource To India Independent Testing
07 Outsource To India Independent TestingoutsourceToIndia
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)nedirtv
 
Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Babul Mirdha
 
Model-Based Testing: Concepts, Tools, and Techniques
Model-Based Testing: Concepts, Tools, and TechniquesModel-Based Testing: Concepts, Tools, and Techniques
Model-Based Testing: Concepts, Tools, and TechniquesTechWell
 
WHITE BOX & BLACK BOX TESTING IN DATABASE
WHITE BOX & BLACK BOXTESTING IN DATABASEWHITE BOX & BLACK BOXTESTING IN DATABASE
WHITE BOX & BLACK BOX TESTING IN DATABASESalman Memon
 

What's hot (19)

01 software test engineering (manual testing)
01 software test engineering (manual testing)01 software test engineering (manual testing)
01 software test engineering (manual testing)
 
Testing 101
Testing 101Testing 101
Testing 101
 
White boxvsblackbox
White boxvsblackboxWhite boxvsblackbox
White boxvsblackbox
 
A survey of software testing
A survey of software testingA survey of software testing
A survey of software testing
 
Testing artifacts test cases
Testing artifacts   test casesTesting artifacts   test cases
Testing artifacts test cases
 
Model-Based Testing: Theory and Practice. Keynote @ MoTiP (ISSRE) 2012.
Model-Based Testing: Theory and Practice. Keynote @ MoTiP (ISSRE) 2012.Model-Based Testing: Theory and Practice. Keynote @ MoTiP (ISSRE) 2012.
Model-Based Testing: Theory and Practice. Keynote @ MoTiP (ISSRE) 2012.
 
Unit testing
Unit testingUnit testing
Unit testing
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 
Testing ppt
Testing pptTesting ppt
Testing ppt
 
Design for Testability
Design for TestabilityDesign for Testability
Design for Testability
 
Software testing: an introduction - 2017
Software testing: an introduction - 2017Software testing: an introduction - 2017
Software testing: an introduction - 2017
 
07 Outsource To India Independent Testing
07 Outsource To India Independent Testing07 Outsource To India Independent Testing
07 Outsource To India Independent Testing
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)
 
Kl assertions 081705
Kl assertions 081705Kl assertions 081705
Kl assertions 081705
 
Model-Based Testing: Concepts, Tools, and Techniques
Model-Based Testing: Concepts, Tools, and TechniquesModel-Based Testing: Concepts, Tools, and Techniques
Model-Based Testing: Concepts, Tools, and Techniques
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
testing
testingtesting
testing
 
WHITE BOX & BLACK BOX TESTING IN DATABASE
WHITE BOX & BLACK BOXTESTING IN DATABASEWHITE BOX & BLACK BOXTESTING IN DATABASE
WHITE BOX & BLACK BOX TESTING IN DATABASE
 

Similar to Design For Testability

Object oriented sad 6
Object oriented sad 6Object oriented sad 6
Object oriented sad 6Bisrat Girma
 
Lecture (Software Testing).pptx
Lecture (Software Testing).pptxLecture (Software Testing).pptx
Lecture (Software Testing).pptxskknowledge
 
Resilience Engineering: A field of study, a community, and some perspective s...
Resilience Engineering: A field of study, a community, and some perspective s...Resilience Engineering: A field of study, a community, and some perspective s...
Resilience Engineering: A field of study, a community, and some perspective s...John Allspaw
 
Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4Billie Berzinskas
 
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databasesAlessandro Alpi
 
Software Engineering Important Short Question for Exams
Software Engineering Important Short Question for ExamsSoftware Engineering Important Short Question for Exams
Software Engineering Important Short Question for ExamsMuhammadTalha436
 
TLC2018 Thomas Haver: The Automation Firehose - Be Strategic and Tactical
TLC2018 Thomas Haver: The Automation Firehose - Be Strategic and TacticalTLC2018 Thomas Haver: The Automation Firehose - Be Strategic and Tactical
TLC2018 Thomas Haver: The Automation Firehose - Be Strategic and TacticalAnna Royzman
 
Code Quality - Security
Code Quality - SecurityCode Quality - Security
Code Quality - Securitysedukull
 
Chapter 3 SOFTWARE TESTING PROCESS
Chapter 3 SOFTWARE TESTING PROCESSChapter 3 SOFTWARE TESTING PROCESS
Chapter 3 SOFTWARE TESTING PROCESSst. michael
 
Creating An Incremental Architecture For Your System
Creating An Incremental Architecture For Your SystemCreating An Incremental Architecture For Your System
Creating An Incremental Architecture For Your SystemGiovanni Asproni
 
1,2,3 … Testing : Is this thing on(line)? with Mike Martin
1,2,3 … Testing : Is this thing on(line)? with Mike Martin1,2,3 … Testing : Is this thing on(line)? with Mike Martin
1,2,3 … Testing : Is this thing on(line)? with Mike MartinNETUserGroupBern
 
Software archiecture lecture05
Software archiecture   lecture05Software archiecture   lecture05
Software archiecture lecture05Luktalja
 
Manual Testing Interview Questions & Answers.docx
Manual Testing Interview Questions & Answers.docxManual Testing Interview Questions & Answers.docx
Manual Testing Interview Questions & Answers.docxssuser305f65
 
Successful Software Projects - What you need to consider
Successful Software Projects - What you need to considerSuccessful Software Projects - What you need to consider
Successful Software Projects - What you need to considerLloydMoore
 
Agile Secure Cloud Application Development Management
Agile Secure Cloud Application Development ManagementAgile Secure Cloud Application Development Management
Agile Secure Cloud Application Development ManagementAdam Getchell
 

Similar to Design For Testability (20)

Object oriented sad 6
Object oriented sad 6Object oriented sad 6
Object oriented sad 6
 
Lecture (Software Testing).pptx
Lecture (Software Testing).pptxLecture (Software Testing).pptx
Lecture (Software Testing).pptx
 
Resilience Engineering: A field of study, a community, and some perspective s...
Resilience Engineering: A field of study, a community, and some perspective s...Resilience Engineering: A field of study, a community, and some perspective s...
Resilience Engineering: A field of study, a community, and some perspective s...
 
Testing Throughout the Software Life Cycle - Section 2
Testing Throughout the Software Life Cycle - Section 2Testing Throughout the Software Life Cycle - Section 2
Testing Throughout the Software Life Cycle - Section 2
 
Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4
 
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
 
Pm 6 testing
Pm 6 testingPm 6 testing
Pm 6 testing
 
Pm 6 testing
Pm 6 testingPm 6 testing
Pm 6 testing
 
Software Engineering Important Short Question for Exams
Software Engineering Important Short Question for ExamsSoftware Engineering Important Short Question for Exams
Software Engineering Important Short Question for Exams
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
TLC2018 Thomas Haver: The Automation Firehose - Be Strategic and Tactical
TLC2018 Thomas Haver: The Automation Firehose - Be Strategic and TacticalTLC2018 Thomas Haver: The Automation Firehose - Be Strategic and Tactical
TLC2018 Thomas Haver: The Automation Firehose - Be Strategic and Tactical
 
Code Quality - Security
Code Quality - SecurityCode Quality - Security
Code Quality - Security
 
Chapter 3 SOFTWARE TESTING PROCESS
Chapter 3 SOFTWARE TESTING PROCESSChapter 3 SOFTWARE TESTING PROCESS
Chapter 3 SOFTWARE TESTING PROCESS
 
Creating An Incremental Architecture For Your System
Creating An Incremental Architecture For Your SystemCreating An Incremental Architecture For Your System
Creating An Incremental Architecture For Your System
 
1,2,3 … Testing : Is this thing on(line)? with Mike Martin
1,2,3 … Testing : Is this thing on(line)? with Mike Martin1,2,3 … Testing : Is this thing on(line)? with Mike Martin
1,2,3 … Testing : Is this thing on(line)? with Mike Martin
 
Software archiecture lecture05
Software archiecture   lecture05Software archiecture   lecture05
Software archiecture lecture05
 
Manual Testing Interview Questions & Answers.docx
Manual Testing Interview Questions & Answers.docxManual Testing Interview Questions & Answers.docx
Manual Testing Interview Questions & Answers.docx
 
System testing
System testingSystem testing
System testing
 
Successful Software Projects - What you need to consider
Successful Software Projects - What you need to considerSuccessful Software Projects - What you need to consider
Successful Software Projects - What you need to consider
 
Agile Secure Cloud Application Development Management
Agile Secure Cloud Application Development ManagementAgile Secure Cloud Application Development Management
Agile Secure Cloud Application Development Management
 

More from Giovanni Asproni

Remote Mob Programming In A High Stakes Environment (Agile Manchester 2023)
Remote Mob Programming In A High Stakes Environment (Agile Manchester 2023)Remote Mob Programming In A High Stakes Environment (Agile Manchester 2023)
Remote Mob Programming In A High Stakes Environment (Agile Manchester 2023)Giovanni Asproni
 
Remote mobprogrammingina highstakesenvironment
Remote mobprogrammingina highstakesenvironmentRemote mobprogrammingina highstakesenvironment
Remote mobprogrammingina highstakesenvironmentGiovanni Asproni
 
Scaling Agile Done Right (XP 2017 version)
Scaling Agile Done Right (XP 2017 version)Scaling Agile Done Right (XP 2017 version)
Scaling Agile Done Right (XP 2017 version)Giovanni Asproni
 
Scaling Agile Done Right (Agile Manchester 2017)
Scaling Agile Done Right (Agile Manchester 2017)Scaling Agile Done Right (Agile Manchester 2017)
Scaling Agile Done Right (Agile Manchester 2017)Giovanni Asproni
 
Creating An Incremental Architecture For Your System
Creating An Incremental Architecture For Your SystemCreating An Incremental Architecture For Your System
Creating An Incremental Architecture For Your SystemGiovanni Asproni
 
Methodology Patterns (Agile Cambridge 2014)
Methodology Patterns (Agile Cambridge 2014)Methodology Patterns (Agile Cambridge 2014)
Methodology Patterns (Agile Cambridge 2014)Giovanni Asproni
 
Writing usableap isinpractice
Writing usableap isinpracticeWriting usableap isinpractice
Writing usableap isinpracticeGiovanni Asproni
 

More from Giovanni Asproni (8)

Remote Mob Programming In A High Stakes Environment (Agile Manchester 2023)
Remote Mob Programming In A High Stakes Environment (Agile Manchester 2023)Remote Mob Programming In A High Stakes Environment (Agile Manchester 2023)
Remote Mob Programming In A High Stakes Environment (Agile Manchester 2023)
 
Remote mobprogrammingina highstakesenvironment
Remote mobprogrammingina highstakesenvironmentRemote mobprogrammingina highstakesenvironment
Remote mobprogrammingina highstakesenvironment
 
Scaling Agile Done Right (XP 2017 version)
Scaling Agile Done Right (XP 2017 version)Scaling Agile Done Right (XP 2017 version)
Scaling Agile Done Right (XP 2017 version)
 
Scaling Agile Done Right (Agile Manchester 2017)
Scaling Agile Done Right (Agile Manchester 2017)Scaling Agile Done Right (Agile Manchester 2017)
Scaling Agile Done Right (Agile Manchester 2017)
 
Creating An Incremental Architecture For Your System
Creating An Incremental Architecture For Your SystemCreating An Incremental Architecture For Your System
Creating An Incremental Architecture For Your System
 
Faking Hell
Faking HellFaking Hell
Faking Hell
 
Methodology Patterns (Agile Cambridge 2014)
Methodology Patterns (Agile Cambridge 2014)Methodology Patterns (Agile Cambridge 2014)
Methodology Patterns (Agile Cambridge 2014)
 
Writing usableap isinpractice
Writing usableap isinpracticeWriting usableap isinpractice
Writing usableap isinpractice
 

Recently uploaded

Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 

Recently uploaded (20)

Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 

Design For Testability

  • 1. Giovanni Asproni email: gasproni@asprotunity.com twitter: @gasproni linkedin: http://www.linkedin.com/in/gasproni Design For Testability What, Why, How 1 /dev/winter 2016 Cambridge
  • 2. “...is the degree to which a software artifact (i.e. a software system, software module, requirements- or design document) supports testing in a given test context. If the testability of the software artifact is high, then finding faults in the system (if it has any) by means of testing is easier.” Software Testability 2 http://en.wikipedia.org/wiki/Software_testability
  • 3. Why? • Testability improves other qualities of the system, as well as delivery time and cost • Testability and system design depend on each other 3
  • 4. Qualities • Maintainability • Evolvability • Use-it-again-ility • I refuse to call it“reusability” • Supportability • Diagnosability • Delivery time • Cost 4
  • 5. Testability Depends On Design (And Vice Versa) 5 “To be tested a system has to be designed to be tested”
  • 6. Design for Test (aka "Design for Testability" or "DFT") is a name for design techniques that add certain testability features to a microelectronic hardware product design. The premise of the added features is that they make it easier to develop and apply manufacturing tests for the designed hardware. The purpose of manufacturing tests is to validate that the product hardware contains no defects that could, otherwise, adversely affect the product’s correct functioning. 6 Design For Testability http://en.wikipedia.org/wiki/Design_for_testing
  • 7. Examples of Software Testability Features • Dependency injection (technique not frameworks!) • Configuration parameters • There are more… 7
  • 8. “All architecture is design but not all design is architecture” Grady Booch Design And Architecture 8 http://handbookofsoftwarearchitecture.com/?p=63 By Grady_Booch,_CHM_2011_2.jpg: vonguard from Oakland, Nmibia derivative work: YMS [CC BY-SA 2.0 (http://creativecommons.org/ licenses/by-sa/2.0)], via Wikimedia Commons
  • 9. Every software-intensive system has an architecture. In some cases that architecture is intentional, while in others it is accidental. Most of the time it is both, born of the consequences of a myriad of design decisions made by its architects and its developers over the lifetime of a system, from its inception through its evolution. In that sense, the architecture of a system is the naming of the most significant design decisions that shape a system, where we measure significant by cost of change and by impact upon use. Design And Architecture 9 http://handbookofsoftwarearchitecture.com/?p=63
  • 10. Architecture Is For (1/2) • Modelling, and reasoning about, important aspects of the system • Quality attributes: scalability, performance, latency, testability, etc., often, cannot (easily) be retrofitted 10
  • 11. Architecture Is For (2/2) • Recording and communicating decisions • Guiding lower level design and implementation decisions • E.g., avoid“TDDing”the system in the wrong direction • Splitting work among teams (Conway’s Law) 11
  • 12. Organizations which design systems are constrained to produce designs which are copies of the communication structures of these organizations. Conway’s Law 12 http://www.melconway.com/Home/Committees_Paper.html
  • 14. 14 Testing shows the presence, not the absence of bugs. Edsger Dijkstra "Edsger Wybe Dijkstra" by Hamilton Richards - manuscripts of Edsger W. Dijkstra, University Texas at Austin. Licensed under CC BY-SA 3.0 via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Edsger_Wybe_Dijkstra.jpg#/media/ File:Edsger_Wybe_Dijkstra.jpg
  • 15. 15 In theory there is no difference between theory and practice. But, in practice, there is.
  • 16. 16 “More than the act of testing, the act of designing tests is one of the best bug preventers known. The thinking that must be done to create a useful test can discover and eliminate bugs before they are coded - indeed, test-design thinking can discover and eliminate bugs at every stage in the creation of software, from conception to specification, to design, coding and the rest.” Boris Beizer
  • 17. Well Chosen Tests • Give us confidence changes don’t break existing functionality • Scale much better than formal methods and formal inspections • And support refactoring activities more efficiently • Most tests can be automated 17
  • 18. Diagnosability 18 Diagnose: identify the nature of (an illness or other problem) by examination of the symptoms Testable software is more diagnosable
  • 19. Cost Of Software • costtotal = costdevelop + costmaintain • costmaintain = costunderstand + costchange + costtest + costdeploy • The above costs are related with each other 19
  • 20. Cost Of Maintenance • Usually costmaintain/costtotal ~ 60% • It is important to write maintainable software 20 “Frequently Forgotten Fundamental Facts about Software Engineering”Robert Glass, IEEE Software, May/June 2001, http://www.eng.auburn.edu/~hendrix/comp6710/readings/Forgotten_Fundamentals_IEEE_Software_May_2001.pdf
  • 21. As of 2011, the average cost per function point in the United States is about $1,000 to build software applications and another $1,000 to maintain and support them for five years: $2,000 per function point in total. For projects that use effective combinations of defect prevention and defect removal activities and achieve high quality levels, average development costs are only about $700 per function point and maintenance, and support costs drop to about $500 per function point: $1,200 per function point in total. 21 How Quality Affects Costs From“The Economics of Software Quality”, Capers Jones and Olivier Bonsignour
  • 22. 22 How Quality Affects Delivery Time % of defects removed Developmenttime Most organisations are somewhere around this point Fastest schedule ~95 100 Source Steve McConnell: http://www.stevemcconnell.com/articles/art04.htm
  • 23. 23 “Quality is an accelerator” John Clifford, Construx Software
  • 25. Testability Measures 25 • Observability: how easy it is to infer internal states from external outputs • Controllability: how easy it is to set some internal states of the system using external inputs
  • 26. Seams 26 Seam: a seam is a place where you can alter behaviour in your program without editing it in that place. Enabling point: every seam has an enabling point, a place where you can make a decision to use one or another.
  • 27. Some Seam Types 27 • Object seams • Link seams • Preprocessing seams • Test hooks
  • 29. 29 public class EventServer implements Runnable {
 
 ... 
 private EventProducer eventProducer;
 public EventServer(EventProducer eventProducer) {
 this.eventProducer = eventProducer;
 ...
 }
 
 @Override
 public void run() {
 ...
 while (isRunning()) {
 try { ...
 Event event = eventProducer.next();
 ...
 } catch (Throwable e) {
 ...
 }
 }
 }
 ...
 } Seam Enabling point
  • 31. 31 public class EventServer implements Runnable {
 
 ... 
 private EventProducer eventProducer;
 public EventServer() {
 this.eventProducer = new SpecialEventProducer();
 ...
 }
 
 @Override
 public void run() {
 ...
 while (isRunning()) {
 try { ...
 Event event = eventProducer.next();
 ...
 } catch (Throwable e) {
 ...
 }
 }
 }
 ...
 } Seam Defined in a different jar
  • 33. A test hook is code used to configure the system to behave differently during testing. Test Hooks 33
  • 34. public class AClass {
 ...
 public void method() {
 ... // Initialise testing using // some external property boolean testing = ...
 if (testing) { // do something } else { // do something else } }
 ...
 } 34 Hook
  • 36. 36 @Test
 public void generatesProxyCorrectly() {
 
 final int value = 10;
 final String expectedMethodName = ServiceInterface.class.getMethods()[0].getName();
 final Object[] args = {value};
 
 serviceCaller = context.mock(ServiceCaller.class);
 proxyMaker = new ServiceProxyMaker(serviceCaller);
 
 context.checking(new Expectations() {{
 oneOf(serviceCaller).call(args, expectedMethodName, serviceAddress, Void.TYPE);
 will(returnValue(null));
 }});
 
 ServiceInterface generatedProxy = proxyMaker.make(serviceAddress, ServiceInterface.class).service();
 generatedProxy.call(value);
 context.assertIsSatisfied();
 }
  • 37. public class AClass {
 ...
 public void method() {
 ... // Initialise testing using // some external property boolean testing = ...
 if (testing) { // do something } else { // do something else } }
 ...
 } 37 Hook
  • 38. 38 public class AClassTest {
 … @Test
 public void methodDoesSomethin() { // Set testing mode to true … // Set some other test context … AClass subject = new ACLass(…)
 subject.method() // Assert something … }
 ...
 }
  • 39. Principle: Keep Test Logic Out of Production Code 39 “Testing is about verifying the behavior of a system. If the system behaves differently when under test, then how can we be certain that the production code actually works? Even worse, the test hooks could cause the software to fail in production!” Test hooks violate this principle. They must be used only in special situations, e.g., a stepping stone in making legacy code testable.
  • 40. Test Doubles • Sometimes we need to test classes that interact with other objects which are difficult to control • The real object has nondeterministic behaviour (e.g., random number generator) • The real object is difficult to set up (e.g., requiring a certain file system, database, or network environment) • The real object has behaviour that is hard to trigger (e.g., a network error) • The real object is slow • The real object has (or is) a user interface • The test needs to ask the real object about how it was used (e.g., confirm that a callback function was actually called) • The real object does not yet exist (e.g., interfacing with other teams or new hardware systems) 40
  • 41. Test Doubles • Dummies • Stubs • Spies • Fakes • Mocks 41
  • 42. Dummies • Dummy objects are passed around but never actually used • E.g., a mandatory argument in a constructor never used during a specific test 42
  • 43. Stubs • Stubs provide canned answers to calls made during the test 43
  • 44. Spies • Spies are stubs that also record some information based on how they were called. (e.g., the number of times a method has been called) 44
  • 45. 45 public class OrderStateTest { private static String TALISKER = "Talisker"; private WarehouseStub warehouse = new WarehouseStub(); @Test public void orderIsFilledIfEnoughInWarehouse() { Order order = new Order(TALISKER, 50); order.fill(warehouse); assertTrue(order.isFilled()) assertTrue(warehouse.removeCalled); } @Test public void orderDoesNotRemoveIfNotEnough() { Order order = new Order(TALISKER, 51); order.fill(warehouse); assertFalse(order.isFilled()); assertFalse(warehouse.removeCalled); } } Adapted from: http://martinfowler.com/articles/mocksArentStubs.html public class WarehouseStub implements Warehouse { public boolean removeCalled = false; public void hasInventory(String brand, int amount) { return “Talisker”.equals(brand) && amount <= 50 } public void remove(String brand, int amount) { removeCalled = true; } ….. }
  • 46. Fakes • Fake objects actually have working implementations, but take some shortcuts which make them not suitable for production (e.g., an in memory database) 46
  • 47. 47 public class OrderStateTest { private static String TALISKER = "Talisker"; private Warehouse warehouse = new WarehouseFake(); @Test public void orderIsFilledIfEnoughInWarehouse() { Order order = new Order(TALISKER, 50); order.fill(warehouse); assertTrue(order.isFilled()) } @Test public void orderDoesNotRemoveIfNotEnough() { Order order = new Order(TALISKER, 51); order.fill(warehouse); assertFalse(order.isFilled()); } } Adapted from: http://martinfowler.com/articles/mocksArentStubs.html public class WarehouseFake implements Warehouse { private HashMap<String, Integer> inventoryByBrand; public WarehouseFake() { inventoryByBrand = new HashMap<>(){{put(“Talisker”, 50);}} } public void hasInventory(String brand, int required) { available = inventoryByBrand.get(brand) return available != null && required <= available; } public void remove(String brand, int amount) { available = inventoryByBrand.get(brand) if (available == null || amount > available) { // Manage the error… } else { inventoryByBrand.put(brand, available - amount); } } ….. }
  • 48. Mocks • Mocks are objects pre-programmed with expectations which form a specification of the calls they are expected to receive 48
  • 49. 49 @Test
 public void generatesProxyCorrectly() {
 
 final int value = 10;
 final String expectedMethodName = ServiceInterface.class.getMethods()[0].getName();
 final Object[] args = {value};
 
 serviceCaller = context.mock(ServiceCaller.class);
 proxyMaker = new ServiceProxyMaker(serviceCaller);
 
 context.checking(new Expectations() {{
 oneOf(serviceCaller).call(args, expectedMethodName, serviceAddress, Void.TYPE);
 will(returnValue(null));
 }});
 
 ServiceInterface generatedProxy = proxyMaker.make(serviceAddress, ServiceInterface.class).service();
 generatedProxy.call(value);
 context.assertIsSatisfied();
 }
  • 50. Mocks Aren’t Stubs • Mocks are meant for testing behaviour • Stubs and all other doubles are generally used for testing state • Classic TDD vs Mockist TDD (Classic school vs London School of TDD) 50 http://martinfowler.com/articles/mocksArentStubs.html
  • 51. APIs • APIs for testing • To query / change the state of the system • To query / change the configuration of the system • Notifications • Logs • They often become support APIs 51
  • 52. Some Examples • Time providers • Notifications of asynchronous events • Timers to check performance parameters • Etc. 52
  • 53. 53 System Test System Entry points for standard users Entry points for testing
  • 54. A big part of designing a software system for testability is about deciding where to put the seams and their enabling points, and to create the necessary APIs for testing 54
  • 55. ...But There Is More • Ease of building the system • Deployability • Configurability 55
  • 56. Deployability • How reliably and easily can the system be deployed in a particular environment? • Does it require some special hardware configuration? • Does it require some special OS configuration? • Does it require a special directory structure? • Etc. 56
  • 57. Configurability • How easily can paths, dbs, and other external resources be configured? E.g.: • Are external resources hardcoded? • Are paths fixed? • Can resources be configured at compile time or runtime? • Too few or too many (or the wrong) options could be a problem 57
  • 58. Tests And Runtimes • Tests and system (partially) in same runtime • Allows the use of dependency injection at the language level • Tests and system in separate runtimes • Dependencies are setup via configuration • May rely more on special APIs for testing 58
  • 59. 59 From:“Growing Object Oriented Software Guided By Tests”
  • 60. 60 Same Runtime: Manage Global State Carefully • Global application state should not spill over • Frameworks must play nicely • Avoid singletons and global variables
  • 61. Same Or Separate Runtimes? • Same runtimes • More fine grained functional testing • Easier TDD at all levels • Separate runtimes • Better for testing qualities (aka“non- functionals”) • Proper full system testing 61
  • 62. 62 Test First at all levels makes it easier to design a system for testability
  • 63. 63 But you will probably need also some upfront design
  • 64. Design Approaches • Big upfront design • No upfront design • Rough upfront design 64
  • 65. Design Approaches (A Different Perspective) • Architecture-indifferent design • Architecture-focused design • Architecture hoisting 65
  • 66. Big Upfront Design “BDUF design for testability is hard because it is difficult to know what the tests will need in the way of control points and observation points on the SUT. We can easily build software that is difficult to test. We can also spend a lot of time designing in testability mechanisms that are either insufficient or unnecessary. Either way, we will have spent a lot of effort with nothing to show for it.” From:“xUnit Test Patterns”
  • 67. No Upfront Design • Works if the design“emerges”by coding and refactoring • Can be quite effective in creating a testable system • Requires a higher level of expertise • Challenging for teams bigger than 3-4 people • Doesn’t work for large systems
  • 68. Rough Upfront Design • Helps the team to keep the big picture in mind • Pull in the same direction • E.g., helps in choosing the right refactoring paths • Useful to hoist important qualities • Design changes and evolves as necessary
  • 69. Architectural Drivers • Qualities (aka, non-functional requirements, or ilities) • Scalability • Security • Performance • Usability • Etc. 69
  • 70. 70 “All quality requirements should be quantified.” Tom Gilb
  • 71. Start Small! 71 “A complex system that works is invariably found to have evolved from a simple system that worked”
  • 72. Travel Light • No speculative design • Remove“reusable”and“flexible”from your dictionary! 72
  • 73. Travel Light: Beware Of Frameworks 73 • Can be very useful... • ...but they can impair testability (among other things)
  • 74. A Walking Skeleton is a tiny implementation of the system that performs a small end-to-end function. It need not use the final architecture, but it should link together the main architectural components. The architecture and the functionality can then evolve in parallel. 74 Walking Skeleton From: http://alistair.cockburn.us/Walking+skeleton
  • 75. 75 Walking Skeleton Database Client GUI Domain layer Server Walking skeleton
  • 76. Risk Based Testing • Least testing • Low likelihood of failure, low consequences of failure • Moderate testing • Low likelihood of failure, high consequences of failure • High likelihood of failure, low consequences of failure • Most testing • High likelihood of failure, High consequences of failure 76
  • 77. What Kind Of Tests? 77 • Manual Tests? • System Tests? • Component Tests? • Unit Tests?
  • 78. 78 Tests are mainly for maintainability and evolution.
  • 79. Tests Need To • Be reasonably simple to create • Or people will not create enough of them, or, perhaps, create just some easy, but not necessarily high value, ones • Provide feedback at the right granularity level (observability and controllability) • Running an entire distributed system to check the implementation of a single class or method is inconvenient, to say the least • Easy and fast to run • Or they won’t be executed as often as they should be (if at all) 79 http://asprotunity.com/blog/system-tests-can-kill-your-project/
  • 80. 80 @Test
 public void generatesProxyCorrectly() {
 
 final int value = 10;
 final String expectedMethodName = ServiceInterface.class.getMethods()[0].getName();
 final Object[] args = {value};
 
 serviceCaller = context.mock(ServiceCaller.class);
 proxyMaker = new ServiceProxyMaker(serviceCaller);
 
 context.checking(new Expectations() {{
 oneOf(serviceCaller).call(args, expectedMethodName, serviceAddress, Void.TYPE);
 will(returnValue(null));
 }});
 
 ServiceInterface generatedProxy = proxyMaker.make(serviceAddress, ServiceInterface.class).service();
 generatedProxy.call(value);
 context.assertIsSatisfied();
 }
  • 81. 81 System Test System Entry points for standard users Entry points for testing
  • 82. • Can be quite complicated to setup and run, especially for distributed systems • Can be very slow, making the feedback loop quite long • May be very difficult or even impossible to run on a developer’s machine • Don’t scale well compared to other kinds of automated tests • Are unhelpful in pinpointing the hiding places of bugs found in production • Their coarse-grained nature makes them unsuitable for checking that a single component, class, function, or method has been implemented correctly. 82 System Tests (Limitations)
  • 83. Can be very difficult to use with distributed teams (especially in large projects) System Tests (Limitations) 83
  • 85. Concluding Remarks • Implications On Design • Added complexity on some dimensions • But added simplicity in others • More stuff to take care of • Tests need to be maintained • ...But it’s still cheaper than running the application manually to smoke test changes... 85
  • 86. Take aways • Testability improves other qualities of the system, as well as delivery time and cost • Testability and system design depend on each other • Test First at all levels helps 86