Visual Studio 2008 has Unit testing support built into it, whereby you can define batches of unit tests and run them as part of your build process.

However, when I tried writing a test against an asmx Web Service, I could not get it to work using the .asmx (endpoint/page) request.

I used a web request style unit test:

[AspNetDevelopmentServerHost("C:\\projects\\fooService", "/")]

public void GetFooTest()
      fooService svc = new fooService();
    Assert(blah, blah);

Unfortunately, this does not work and most likely you will get a 404.
I got this error when I ran my unit test:

Could not connect to the Web server for page ‘http://localhost:62534/fooService’. The remote server returned an error: (404) Not Found.. Check that the Web server is running and visible on the network and that the page specified exists.

I tried a few hacks like adding a default page to the service project and specifying that in the UrlToTest attribute, etc. but to no avail.

Finally, I resorted to just adding a Service Reference to the target and removed the three web attributes. This means that my service class is instantiated directly and not through a web service request but honestly I don’t care about the transport part. I’m mainly interested in testing functionality anyway.

Hope this post helps…

About these ads