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