views:

38

answers:

1

Hi,

I am new to WCF. I wrote a service and consumed the service in client application. Now I want to write unit tests for both the server and client.

What are the guidelines I should fallow to write unit tests for WCF.

I googled and came across different ways to Unit test WCF. But really not sure which one is better.

I am using vs2008.

Thanks,

+1  A: 

Hello,

what are you really looking for? Do you want to test the service and the client functionality separately (unit test) or integration of the client with the service (integration test)? Unit tests are usually used to test single functionality. You can write set of simple unit tests to test all execution paths in tested unit. Integration tests are used to check configuration and integration between components. You usually don't write integration test for each execution path in your system because the complexity and number of execution paths accross all layers can be to big.

To unit test the service you just need to write unit tests for your service contract implementation (service class).

To unit test the client you have to design the client so that a dependency to the service is injected in property or constructor (look for Inversion of control and dependency injection). Then you can write the test and inject mock/fake of your service = you will test the client functionality without using real service implementation.

Integration test can be simple test which calls client functionality wich uses directly your service implementation. In that case you will test all layers of your application in single execution path.

Best regards, Ladislav

Ladislav Mrnka
Hi Ladislav, Which IOC Framework do u recommend?
Saghar
I'm forced to use Unity. In my hobby project I used Windsor.Castle but as I heard Spring.net and StructureMap also offer very good IoC containers.
Ladislav Mrnka