Myles McDonnell
Myles McDonnell

Reputation: 13335

WebAPI app and integration tests in same solution

I have a WebAPI app and an integration test suite for the app that calls the API over HTTP. Currently I run the integration suite in one instance of visual studio 2013 and manually start the WebAPI app in another instance, to run on IIS Express.

Is it possible to configure VS2013 such that I can have the test suite and the app in the same solution and simply run the test suite (I'm using nunit and the resharper running) at which point it will take care of building and starting the web app?

Upvotes: 1

Views: 1594

Answers (2)

fabriciorissetto
fabriciorissetto

Reputation: 10063

I really don't understand why the VS doesn't support this. It seems to be a very common issue.

Anyway... I've found an (ugly) workaroud to it.

Open your solution twice (that means, two instances of VS open with the same solution):

  • In the first one VS:
    • Run the Web API project in debug mode
  • In the second one:
    • Unload the Web API project (the tests must be built before they run, the building process fails if the Web API project is "loaded" because the output dlls can not be overwritten - they are being used by the other window)
    • Run the unit tests! :)

Upvotes: 2

Darin Dimitrov
Darin Dimitrov

Reputation: 1038930

You could configure the WebAPI in a self-host. Then in your test fixture setup you will start the host and tear it down after each test. Then all your tests will be configured to hit the locally hosted API.

Upvotes: 2

Related Questions