简体   繁体   中英

web service testing without IIS

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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM