Stephen's suggestion is to end WCF plumbing for testing. This will certainly work and validate much of the business logic, but I would like my automatic integration tests to also verify WCF interactions.
I have successfully achieved this in automatic tests for my project.
Note that the WCF client and WCF host can share the same process. In this case, it still makes calls through the WCF structure with all the limitations and difficulties. And your WCF services will pick up the connection string from the configuration file of the test project.
To illustrate this, here is what the configuration file looks like if the client and the service are in the same process.
<configuration> <connectionStrings> <add name="ContractsManager" providerName="System.Data.SqlClient" connectionString="Data Source=localhost;Initial Catalog=ContractsManager_AutoTest;Integrated Security=True;Pooling=False;Asynchronous Processing=true;Application Name=CmAutoTests" /> </connectionStrings> <system.serviceModel> <client> <endpoint name="LoggingService" address="net.tcp://localhost:9612/loggingService" binding="netTcpBinding" contract="ContractsManager.ILoginService" /> </client> <services> <service name="ContractsManager.LoginServiceImpl"> <endpoint address="net.tcp://localhost:9612/loggingService" binding="netTcpBinding" contract="ContractsManager.ILoginService"> </endpoint> </service> </services> </system.serviceModel> </configuration>
Thus, your automated tests will find errors specific to WCF (for example, an exception not specified in the fault contract). I was saved by this today: my code had an error that meant that the channels were closed properly. My tests continued to hang because the throttle limit was reached. It took some time to understand, but I am grateful that the error did not find it in production.
Your test suite should configure service hosts before starting the first test. (I tried setting up and tearing down the service hosts with each test, but it runs too slowly).
Good luck.
source share