开发者

Test Driven Development For Complex Methods involving external dependency

I am implementing a Service Contract for WCF Service.

As per TDD I wrote a test case to just pass it using hardcoded values.

After that I started to put real logic into my Service implementation. The actual logic relies on 3-4 external service and database.

What should I do to my original test case that I wrote ? If i Keep it same in order to make test pass it will have to call several other external services.

So I have question in general what should I do if I write a test case for a Business Facade first开发者_C百科 using TDD and later when I add real logic, if it involves external dependency.


Utilize a mocking framework (with dependency inversion or just a factory) so you can inject fake dependencies into the object. These can then then just return canned responses and/or be checked that the class utilizes the dependencies how you intended.

As an example, if your code calls a repository to save, we don't really care in the business method test that the repository did actually save to a persistance store, only that it got called and returned some data if required. What you're really testing is how your code reacts to what the dependency returned, or if it was utilzed correctly - but not the dependency's actual functionality

Ideally the first test should have been representative of how the class/method will work and return data, so the test would still be valid once you're finished.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜