How to debug/unit test webAPi in one solution

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

    If you have an API project and you created an end-to-end unit test project for the API (meaning you are testing the API directly using HttpClient, WebClient, or other http client wrappers), you have to enable "Multiple startup projects" on the solution. Follow steps below:

    1. Right click on the solution file and select properties.
    2. Select "Multiple startup projects" radio button.
    3. Select the "Start" action in the drop-down for the web api project and unit test project.
    4. F5 to start in debug mode.
    5. You will get an error dialog saying "A project with an output type class library cannot be started directly". This is fine since the unit test project is just a class library (not an executable so there is no main/start method). Just click "Ok" the dialog.
    6. On the unit test method you want to test, right click and select "Debug Unit Tests" to start debugging.

提交回复
热议问题