简体   繁体   中英

Run another project in the same solution while debugging unit test project in visual studio (2019)

I have a unit test project that needs a WebApi project to be run for passing some data to the main class library project in the same solution. for this purpose, I open another instance of visual studio and run this service on it and debug unit test in another instance.

Is there any solution to run depended projects while debugging or running unit tests in the same instance of visual studio?

Right click on the Solution node , select Properties .
You should see a list entry named Startup Project where you can choose from a single project startup or multiple projects startup.

Just activate the Multiple Startup Projects option and set the Action column to Start for the projects that you want to start together.

Remember to arrange the order of startup if it is important for your application (for example if the Test project requires the API already loaded at its startup)

this is confusing, so you are saying you have unit tests which depend on data from an API? Then you went down the wrong path, what you have right now is not unit tests.

Abstract away the code that calls the API so it can be mocked / replaced with values as required.

Your first piece of work should be to eliminate the API dependency, not to find ways of adding it in.

For example if one test needs some particular data from the API, then change the code to not call the API and pass the data in as a parameter. Then in your test you just replace that with whatever you want for your test, without having to worry about an API. This way you can even eliminate mocking, which makes a test a lot simpler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM