views:

169

answers:

3

Hello, I'm starting to TDD and I want to know if it is a bad practice to add a service reference to test my project or if I just mock a fake service on my tests that depends of the WCF service.

+2  A: 

Yes it is a bad practice to add service references to a unit testing project. You could use the generated service contract interface to mock the real WCF service behavior in the test.

Darin Dimitrov
Also if you are into testing the WCF plumbing you could use your test framework thread as a host(MSTEST or other). This assumes you are not using something like IIS as a host.
Adam Fyles
A: 

Rather than using a service reference you could mock out a ChannelFactory using your service contract.

Rus
+1  A: 

Having a service ref is possible a bad way to go, you could consider implementing the Gateway Pattern, e.g. IMyFooServiceGateway as an additional abstraction layer. This way you might be able to make the app more loosely coupled and gain some additional testability (in you test project you'd reference the segregated assembly containing IMyFooServiceGateway and either hand-create a mock that implements IMyFooServiceGateway or use a mock framework like Rhino Mocks to create one for you.

Jason Roberts