Please enable JavaScript.
Coggle requires JavaScript to display documents.
AOUT3 - Coggle Diagram
AOUT3
Steps
Find the interface (not in the pure O.O. sense)
Add layer of indirection
replace underlying implementation
indirection levels
layer 1 the variable inside a class
add a constructor argument that will be used as the dependency
layer 2: the dependency returned from the factory class into the class under test
layer 3 the factory class that returns the dependency
replace the actual factory for a fake factory
conclusion
more inderection => more control => less easy to understand
some new attributes
internal
[InternalsVisibleTo]
[Conditional]
not for constructors just methods
if
Stubs
is
a controllable replacement for an existing dependency (or collaborator) in the system
is used for
not dealing directly with the external dependency
vs Mock
Mock is like a stub but you assert against the mock (you DO NOT assert against a stub)
external dependency
is
and object in your system that your code under test interacts with and over which you have no control
examples
file systems
time
memory
threads
Refactoring your desing to be more testable
concepts
refactoring
change the code without changing the code's functionality
dependency-breaking refactorings
type a
abstracting concrete objects into interfaces or delegates
examples
Extract an interface to allow replacing underlying implementation
the name is contains the FAKE word not STUB or MOCK, because it can be used as a mock or a stub
type b
refactoring to allow injection of fake implementations of those delegates or interfaces
examples (dependency injection)
inject stub implementation into a class under test
inject a fake at the constructor level
inject a fake as a property get or set
inject a fake just before a method call
seams
places in your code where you can plug in different functionality such a subs classes, adding a constuctor parameter, adding a public settable property, makeing a method virtual so it can be overridden, etc
this is what you get by implementing the Open-Closed Principle where a class's functionality is open for extenuation, but its source code is closed for direct modification
HIDING
you can put seam statements under conditional compilation