开发者

web service testing without IIS

开发者 https://www.devze.com 2022-12-09 10:22 出处:网络
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.

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.


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号