Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Speedup WCF “unit” tests? (Creating/closing the ServiceHost is slow...)

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?

like image 679
Ian Ringrose Avatar asked Nov 26 '09 11:11

Ian Ringrose


1 Answers

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.

  • What kind of errors do you expect to be found?
  • Is there really no other way to test it? (eg. we found another way for serialization problems)
  • How big is the chance that this kind of error occurs? Is it easy for developers to avoid it?
  • How hard would it be to find it by manual testing? (eg. serialization problems are hard to find, because just one property could be lost, on the other hand, if the client can't even connect, it's very easy to find)
like image 125
Stefan Steinegger Avatar answered Oct 05 '22 23:10

Stefan Steinegger