Search code examples
asp.netasp.net-web-apiintegration-testingweb-api-testing

web api integration testing


I have an integrationtest project and a web api project in the same solution. The integration tests use RestSharp to call the web api. When running the integration tests I want the web api project to launch first. Is that possible?


Solution

  • The best way I've found to do this is to Self Host the target WebApi project. Then, if you want to run these tests on a build server etc, you don't need a web server installed.

    This is a pretty good walk-through on setting up a Self Host.

    Essentially, you use the HttpSelfHostServer class with HttpSelfHostConfiguration to host the target project.