I am in the process of writing some test for a server that is implemented in WCF, as the messages are complex and call-backs are made to the clients I wish to include WCF in the tests.
(You may wish to call these “fit” or “integration tests” not unit tests, the code on both side of WCF will have more detail unit test that don’t use WCF.)
As my server keeps state and I wish to check that all channels shut down without errors, I have code like:
[SetUp]
public void SetUp()
{
//TODO find a fee port rathern then hard coding
endPointAddress = "net.tcp://localhost:1234";
mockEngineManagerImp = new Mock<IEngineManagerImp>();
EngineManager engineManager = new EngineManager(mockEngineManagerImp.Object);
serviceHost = new ServiceHost(engineManager);
serviceHost.AddServiceEndpoint(
typeof(IEngineManager),
new NetTcpBinding(SecurityMode.None),
endPointAddress);
serviceHost.Open();
}
[TearDown]
public void TearDown()
{
serviceHost.Close();
}
However my tests are very slow....
How can I speed up the creation and destroying of my ServiceHost?
We stopped writing integration tests which use WCF. It was too much of an effort to make the whole system up and running within reasonable time.
Instead, we're testing the logic isolated. Serialization of data contracts, which is the biggest source for errors in this area, is also tested independent from WCF (just calling the DataContractSerializer). After some initial effort, WCF itself didn't make trouble until now.
I'm not sure if this helps.
Edit: Think of what you are actually testing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With