Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug/unit test webAPi in one solution

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 instance I have the unit test, in the second vs instance I have the webapi running in localhost.

Is there a better way to do this?

Is the preferred way to unit test is to have a reference to the WebAPI project?

I want to consume it using httpClient and not have to reference it in the UnitTest Project.

so in my UnitTest method it would have a baseAddress of "http://localhost:1234"

this would be where the WebAPI if launched from the same solution would be hosted.

The current way I am debugging requires me to launch a second Visual Studio instance with the same solution loaded and have one running the WebAPI project, while the other Visual Studio runs the Unit Test project.

like image 549
Arcadian Avatar asked Oct 22 '15 16:10

Arcadian


1 Answers

  1. Start debugging Unit Test
  2. While on the first line of your test code or before calling your local web api project
  3. Right click on your web api project and Debug > Start new instance
like image 179
Barbaros Alp Avatar answered Oct 14 '22 02:10

Barbaros Alp