tdd


BDD/TDD: can dependencies be a behavior?


I've been told not to use implementation details. A dependency seems like an implementation detail. However I could phrase it also as a behavior.
Example: A LinkList depends on a storage engine to store its links (eg LinkStorageInterface). The constructor needs to be passed an instance of an implemented LinkStorageInterface to do its job.
I can't say 'shouldUseLinkStorage'. But maybe I can say 'shouldStoreLinksInStorage'.
What is correct to 'test' in this case? Should I test that it stores links in a store (behavior) or don't test this at all?
The dependency itself is not an expected behavior, but the actions called on the dependency most certainly are. You should test the stuff you (the caller) know about, and avoid testing the stuff that requires you to have intimate knowledge of the inner workings of the SUT.
Expanding your example a little, lets imagine that our LinkStorageInterface has the following definition (Pseudo-Code):
Interface LinkStorageInterface
void WriteListToPersistentMedium(LinkList list)
End Interface
Now, since you (the caller) are providing the concrete implementation for that interface it is perfectly reasonable for you to test that WriteListToPersistentMedium() gets called when you invoke the Save() method on your LinkList.
A test might look like this, again using pseudo-code:
void ShouldSaveLinkListToPersistentMedium()
define da = new MockLinkListStorage()
define list = new LinkList(da)
list.Save()
Assert.Method(da.WriteListToPersistentMedium).WasCalledWith(list)
end method
You have tested expected behavior without testing implementation specific details of either your SUT, or your mock. What you want to avoid testing (mostly) are things like:
Order in which methods were called
Making a method, or property public just so you can check it
Anything that does not directly involve the expected behavior you are testing
Again, a dependency is something that you as the consumer of the class are providing, so you expect it to be used. Otherwise there is no point in having that dependency in the first place.
LinkStorageInterface is not an implementation detail - its name suggests an interface to to an engine. In which case the name shouldUseLinkStorage has more value than shouldStoreLinksInStorage.
That's my 2 pennies worth!

Related Links

c# TDD first time in ServiceBase
Integration card at the end of a user story (TDD)
Software development methodology for startup less than 3 friends [closed]
how can i automate using mstest?
Properly testing promises attached to $scope
What are some good services or tools to use for remote pair programming?
How to write independent functional test
Is it possible to study BDD without prior TDD experience? [closed]
testing with automated testing
TDD, How to write tests that will compile even if objects don't exist
first time TDD help needed
How to install PHPUnit using composer in Windows 07 64 bit?
Meteor test driven development [closed]
How will I test my private methods in ios? [closed]
Sending autotest / guard desktop notifications from Vagrant Ubuntu VM to host (W7 and OS X)
Are utility classes allowed with the Single Responsibility Principle (SRP)

Categories

HOME
compiler-construction
xamarin
pdf
gitlab
wso2
gerrit
netbeans
zeromq
ngrx
drivers
comparison
view
graphql
youtube-api-v3
sqlite3
webpack-2
yum
opengl-es-2.0
azure-storage-tables
here-api
dax
jplayer
alignment
flask-wtforms
circuit
iolanguage
windows-7-x64
footer
oracle-coherence
nhibernate-envers
shared-hosting
conemu
dcevm
claims-based-identity
vlsi
su
maxmind
compatibility
preg-match
google-rich-snippets
galsim
google-sites-2016
column-family
atl
git-merge
disassembling
x11-forwarding
gesture
mixture-model
event-driven
starteam
unobtrusive-validation
elasticsearch-plugin
azure-ml
lumberjack
janrain
no-www
gpx
jsch
osx-mavericks
boost-multi-index
blogengine.net
veracode
typed-lambda-calculus
android-cursor
sybase-asa
deadbolt-2
adxstudio-portals
intrusion-detection
bstr
lttng
angstrom-linux
hover-over
pickadate
pagerank
independentsoft
unity-networking
qtableview
jqgrid-formatter
computer-algebra-systems
wyam
sankey-diagram
createprocessasuser
remobjects
oberon
pretty-print
c++03
angularjs-ng-click
preferences
has-many-through
htmlcleaner
hippomocks
poller
resty-gwt
cloud-connect
stxxl
fmod
prettify
terminal-services
pyhdf
oam
dotnetnuke-5
bulkloader
gridcontrol
spring-validator
smtp-auth
free-variable
distutils
rdoc
broken-links
viewswitcher
ohm
cufon
external-accessory
horizontal-accordion
yui-datatable
yslow
dentrix
mirah
photoshop-cs4
ti-dsp
swing-app-framework
data-acquisition
multiple-languages
wsdl.exe
document-conversion

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App