Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run other project when running unit tests in Visual Studio 2013

I have a setup with some VS projects which depend on each other. Simplified, imagine these projects:

  1. API Project (ASP.NET WebAPI 2)
  2. DummyBackendServer (WinForms with a WCF Service)
  3. API.Test Project (Unit Test Project which should Test API-Project's Controllers)

Usually, there would be (for example) an android client, which connects to the API-Server (1) and requests some information. The API-Server would then connect to the DummyBackendServer (2) to request these information, generate an appropriate format and send an answer to the android client.

Now I need to create some unit tests for the API-Server. My problem is, that I don't find a way to tell VS to start the DummyBackendServer (2), when it runs the unit tests. When I first start the DummyServer I can't run the tests, because the menu option is grayed out.

So, is there any way to tell VS to start another project the tests depend on?

like image 688
Rasioc Avatar asked Dec 20 '25 20:12

Rasioc


2 Answers

For anyone who doesn't want to unit test the correct way and just want to run multiple projects in the same soluition, here is the answer.

Rightclick the backend project -> Debug -> Start without debugging.
The interface will not grey out so you can start other projects.

Start test with rightclick -> Run Tests
Or run your frontend with debugging as usual by having it set as startup project (Bold in the Solution Explorer) and clicking F5 or the green arrow, Start With Debugging.

like image 92
BjornGrylls Avatar answered Dec 22 '25 10:12

BjornGrylls


Divide and conquer!

If the test (some will say that those are not unit test, but that is not part of this question) requires some services to be up - make that happen! Have them deployed to some dev or staging environment, then you only need to configure the connection from the API test assembly.

I would split the solution in two and call them integration tests. If you want them to bee unit test you have what you need from the post above.

like image 45
Jocke Avatar answered Dec 22 '25 12:12

Jocke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!