How to debug/unit test webAPi in one solution

前端 未结 7 1844
借酒劲吻你
借酒劲吻你 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:52

    In the current version of ASP.Net Core the official solution to this is to use the Microsoft.AspNetCore.TestHost Nuget assembly which creates a simulated web server hosting the web project in the test project.

    Details on usage can be found here: https://docs.microsoft.com/en-us/aspnet/core/testing/integration-testing

    On the one hand it feels like a bit of a fudge because by what definition is it genuine integration testing if a real web server is not involved, on the other hand it does at least work pretty seamlessly once you get it set up.

    0 讨论(0)
提交回复
热议问题