How to debug/unit test webAPi in one solution

前端 未结 7 1846
借酒劲吻你
借酒劲吻你 2021-02-12 22:17

Is there a way to unit test or debug a web api in one vs solution? I am consuming the WebAPI using HttpClient and have two instances of VS up to do this.

in 1 VS instan

7条回答
  •  你的背包
    2021-02-12 22:46

    As Daniel Mann stated, this isn't unit testing. This is integration testing. You are running up the entire project and testing everything.

    If you want to unit test you webapi controllers, just add a unit test project to webapi project and create unit tests. You want to focus on testing only a single class at a time. Mock/Fake any dependencies of that class.

    Here's a nice example from Microsoft http://www.asp.net/web-api/overview/testing-and-debugging/unit-testing-with-aspnet-web-api

    but if what you are looking for is running the test you have in a single solution. Just put both projects in the same solution. Right click on the solution in the solution explorer. Select "Set StartUp projects." select "multiple startup projects" and select the projects you want to startup at the same time.

提交回复
热议问题