How to test an API service in Visual Studio

10,380

Off the top of my head: Right click the service project and choose Debug >> Start New Instance. Then start the debug on your web "test" application. You should now be able to accomplish what you desire. (since this is off the top of my head, if it fails, it is very close to the right answer).

A better option is to move the functionality into a class library and make the web service project very thin (essentially returning calls from the class library assembly). You can then test the business functionality by using a unit test library, like MSTest (built in with most team system SKUs of Visual Studio) or nUnit (etc). Sure the tests will likely be integration tests, but you accomplish two good things:

  1. You get the UI out of the testing equation so you can focus on the business logic
  2. You create repeatable tests (think science, not art)

I find it a really bad pattern to have moving parts in a UI project, unless the moving parts are focused on presentation of data. And, yes, I see web services as a UI, even though the user is an application rather than a human body.

Share:
10,380
BrianKE
Author by

BrianKE

Updated on June 04, 2022

Comments

  • BrianKE
    BrianKE almost 2 years

    How can I use the debug a service within Visual Studio 2010? What I would like to do is step thru the code as the request is being processed.

    I am running the service by right clicking on the web site project (C:...\APIServiceSite) within the solution and selecting "View in Browser". Everything runs OK and I get the expected results back from the service but I cannot find a way to step thru the code which is in a another project (APIService) within the same solution.