1

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?

0

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Sounds ideal, however these instructions asp.net/web-api/overview/hosting-aspnet-web-api/… assume you will define the controllers etc in the project that is the entry point. I have a project for the test suite and a project for the web app so not sure this will work? Perhaps it will and I just need to work out how it all hangs together.
You can have the controllers in a separate assembly, just write a custom IAssembliesResolver as shown here: developer.com/net/asp/self-hosting-an-asp.net-web-api.html. This will allow you to load the controllers from the actual assembly where they live instead of using the current unit test assembly that contains the self-host.
Great. I'm using StructureMap.MVC will this all get initialized properly just by virtual of the custom resolver, or will I have to do that explicitly?
As long as you call the method to bootstrap your DI it will work.
I have a suspicion that github.com/webadvanced/Structuremap.WebAPI2 will not work with OWIN self host as it uses nuget.org/packages/StructureMap.MVC5 and MVC5 does not self host :(
2

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! :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.