views:

3098

answers:

8
+7  Q: 

WCF Unit Test

How to unit test WCF services? Any 3rd Party tools available?

+3  A: 

What exactly do you want to test? Connectivity or service methods?

Cool thing about WCF is that you can just define interfaces (err, contracts) and test them as regular code. Then you can assume that they will work via any connection type supported by WCF.

Connectivity can be tested by hosting your service directly in UT or on development web-server.

As for tools, you there are tons of unit testing frameworks: NUnit, built-in tests in Visual Studio, xUnit, etc, etc.

You can download "Visual Studio 2008 and .NET Framework 3.5 Training Kit" and ".NET Framework 3.5 Enhancements Training Kit" if I recall correctly there were samples for WCF unit tests

aku
+1  A: 

If one really wants to test WCF services, it's best to go with integration tests that actually exercise the client-server connectivity part of it.

cruizer
+6  A: 

As aku says, if you're testing service methods (ie code behaviour) then you can unit test that directly and bypass the WCF infrastructure. Of course, if your code depends on WCF context classes (like OperationContext) then I suggest introducing wrappers much like ASP.NET MVC does for HttpContext.

For testing connectivity, it will depend on the type of endpoints you have configured. In some cases you can just self-host your WCF service inside the unit test (like you would with a WCF Windows Service) and test that.

However, you may need to spin up the ASP.NET Development Web Server or even IIS if you want to test WCF behaviour specific to those hosting environments (ie SSL, authentication methods). This gets tricky and can start making demands on the configuration of everyone's development machine and the build servers but is doable.

Jason Stangroome
+1  A: 

You can use Typemock Isolator to do that. Here are a couple of posts on the issue of testing the client side, and the server side. You can do that without any dependency, including a config file.

Gil Zilberfeld Typemock

+2  A: 

If you want to test the actual running service then SoapUI is free and has some excellent features. The only caveat is that I have only tried it with the Basic HTTP binding.

Thomas Bratt
A: 

I have seen SOA Test used to evaluate performance and scalability tests on WCF services, if this is what you seek. I have no information on cost or liscencing.

In our case, we captured the messages from our UI in order to perform automated testing.

Berkshire
+1  A: 
+1  A: 

Typemock Isolator is a tool for unit testing wcf services, amoung other things...