tags:

views:

78

answers:

3

What is the best way to test web service using NUnit. I want it to be automated, i.e, I don't want to have a separate process to host the web service for the testing code to consume.

+1  A: 

The web service is just a plain-old-.net class. You can instantiate it directly and call its methods in a unit test.

That won't allow you to test http specific aspects of web services like authentication at the protocol level, but I would say that there's no getting around using a web server for that.

jthg
A: 

Depends. If it's an asmx, you can use HostableWebCore on Vista and higher. If it's WCF, just self-host by creating an instance of ServiceHost in your process. You could directly instantiate the service impl, but if you have any HTTP-isms (HttpContext, Request/Reponse access, cookies, etc), you'll have to mock them.

nitzmahone
A: 

It depends on what you want to test. It's possible to do full integration tests and there is some value in that (checking serialization, for instance). One simple way to get good test coverage with minimal work is as follows:

  1. Write one or more plain old classes that do the real work (use TDD if desired)
  2. Test these classes in isolation
  3. Have your WebMethods delegate to these classes.
TrueWill
I think that would be the direction I'll head.
Ted Lee