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

What is Test Driven Development? Does it require to have initial designs?
TDD in Visual Studio 2008 add-ins
What causes Cassini to load when I run a unit test [duplicate]
Do you TDD for debugging fix?
Experiences with Test Driven Development (TDD) for logic (chip) design in Verilog or VHDL
TDD - When is it okay to write a non-failing test?
What's the point of testing fake repositories?
Separating rapid development from refactoring/optimization
Interface Insanity
unit test installers
Has anybody used Unit Testing as a way to learn programming?
Testing only the public method on a mid sized class?
How to develop complex methods with TDD
How can I remove the “Test With” menu left after uninstalling TestDriven.NET?
“Code covered” vs. “Code tested”?
IoC & Interfaces Best Practices

Categories

HOME
client
atom-editor
netsuite
appx
rsyslog
bookshelf.js
gis
cvs
icloud
baqend
alpha
facebook-messenger-bot
vifm
reveal.js
commonmark
carthage
uitypeeditor
karma-jasmine
custom-wordpress-pages
one-hot-encoding
abi
claims-based-identity
underflow
maquette
atlassian-crucible
libssl
vision
ioio
karaf
column-family
webtest
accelerate-framework
http-referer
catalog
disassembling
space-complexity
grid.mvc
dynamic-reports
thin
segment
babel-core
fault
dropbox-php
elgg
tactic
media-player
namecoin
cudafy.net
spring-cache
minimization
setuptools
url-pattern
asp.net-4.5
qgraphicsview
hover-over
bgp
r-tree
wso2cloud
jqgrid-formatter
security-testing
riak-cs
createprocessasuser
truevault
qcodo
eventual-consistency
pygit2
smtp-auth
propertyeditor
dsn
parametric-equations
regsvr32
netbeans-6.9
dotnethighcharts
cufon
gnu-prolog
mod-auth
google-friend-connect
dmx512
icanhaz.js
modelstate
user-friendly
anti-piracy
nerddinner
mediarss
uiq3

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App