How to run a test at the same time a web project is being debugged?
Asked Answered
A

7

29

In some of the solutions we have ASP.NET/WCF web project and a test project. Some of the tests run against ASP.NET development web server using http://localhost:port/.... In VS2010 while the ASP.NET/WCF web project was being debugged, the test runner could run the tests and if there were any breakpoints in web project, the debugger would break the execution. This seems to have been disabled/removed in VS2012.

When the ASP.NET/WCF web project is debugged (launched by pressing F5 or via attach process), both the TEST->Run and TEST->Debug sub-menus are disabled. In VS2010 only Test->Debug sub-menus were disabled while Test->Run sub-menus were still enabled. We use this way to easily debug the services within the web project. Any way to get that behavior back or workaround?

Debugging While Running on ASP.NET Development Server doesn't seem to be applicable to VS2012 or at least I can't get it to work.

Advowson answered 30/8, 2012 at 19:30 Comment(5)
@Robert, I thought tags should not be included in the questions. Also, the question is about "how to run a test at the same time when the web project is being debugged" rather than functioning of the breakpoints. In VS2012 the tests can't be run at all.Advowson
That is why I am asking the question. If the debugger is running and the web project is being debugged, we can't run the test. All the menus under TEST->Run and TEST->Debug are disabled. This wasn't the case in VS2010. We have tried on multiple machines and on multiple projects (converted to VS2012).Advowson
When crafting a title, I think about how it might look in Google. Since the most popular tag (ASP.NET in this case) is appended to the beginning of the title in Google, adding tags to the beginning of a title makes no sense at all. It is, however, OK for tags to appear "naturally" in the middle or end of a title if it makes it a better title for Google.Autosome
As to your problem, your best course of action may be to decouple your classes so that unit tests can be run on them independently of your ASP.NET application. Visual Studio rightly believes that, when you run your application, that is the test.Autosome
Well, we have several projects like that and we have only started to convert those to VS2012. Since it was working in VS2010 (right way or wrong way), we were hoping that it would work the same way in VS2012.Advowson
A
3

I ended up writing a quick addon. It turns out that like VS2012, VS2012 test runner can also run the tests when the web project is being debugged. It is just that menu options are disabled.

Advowson answered 30/10, 2012 at 22:9 Comment(2)
That's a great idea. Unfortunately when I tried your addon it fails to load with error number 80004005. This is with VS 2012 Ultimate, Update 2.Lanchow
Thanks for the effort. I got it to run in VS 2013 Community by following these instructions (#21662723). For me no error messages, but VS asks to stop debugging when the "Run all tests in context" option is used, and doesn't run tests.Kalli
K
14

In VS2013 the situation is the same: the options for running / debugging tests are greyed out while the project is being run/debugged. This is a shame especially for projects like web API's where tests for calling the API via HTTP (as opposed to creating an instance of the Controller class and circumventing any network traffic) are very useful as they are closer to what the end users of the API will experience.

As a workaround, you can either open the same solution in a separate instance of VS, or create a separate solution with the same projects, specifically for testing. Debug in the first VS instance, run tests in the second one.

Kalli answered 16/1, 2015 at 16:10 Comment(0)
L
8

If you have a solution with WCF applications and tests calling them, you can debug the applications using the tests by calling Debug All Tests or Debug Selected Tests without a previous Start Debugging (F5).

Configure your solution to Multiple Startup Projects with None set in all actions and configure your WCF applications to the start action Don’t open a page. Wait for request. With this configuration the development web server starts if you select Debug All Tests or Debug Selected Tests.

Lamelliform answered 17/1, 2013 at 17:6 Comment(0)
M
7

Here is a workaround to debug a single unit test along with a web server. It relies on Debugging Multiple Processes (excludes MSVS Express):

  1. Start web server (non-debug), note its process id (IIsExpress icon -> Show All Applications)
  2. Place a breakpoint at first line in test
  3. Start Debuging the Unit Test, wait for it to stop at the breakpoint.
  4. Debug -> Attach To Process, enter web server process id

Both the test and server are running live in the debugger.

Metamathematics answered 21/4, 2017 at 3:9 Comment(0)
A
3

I ended up writing a quick addon. It turns out that like VS2012, VS2012 test runner can also run the tests when the web project is being debugged. It is just that menu options are disabled.

Advowson answered 30/10, 2012 at 22:9 Comment(2)
That's a great idea. Unfortunately when I tried your addon it fails to load with error number 80004005. This is with VS 2012 Ultimate, Update 2.Lanchow
Thanks for the effort. I got it to run in VS 2013 Community by following these instructions (#21662723). For me no error messages, but VS asks to stop debugging when the "Run all tests in context" option is used, and doesn't run tests.Kalli
L
2

Try this:

  1. Place a breakpoint in the first line of your unit test method.
  2. Start debugging your unit test.
  3. Once it hits the first line in your unit test, start a new instance of the other projects you need running.
Loera answered 10/4, 2019 at 18:59 Comment(1)
in VStudio 2013, I did what you said, a little different, first debug tests, then attach to process, but it's practically the same.Olgaolguin
O
0

This is not a pretty solution, but it works. Using Azure DevOps TFS Version Control, create a branch of your current project. Open the solution for your project, in the other branch, in another instance of Visual Studio at the same time as your main project is running in the first/original instance of Visual Studio. Then, run your web project in your first/main Visual Studio instance. Now, run your unit tests from the other instance of Visual Studio. Voila.

To keep them in sync, you can do Merges from one branch to the other.

Otes answered 20/4, 2020 at 2:19 Comment(0)
C
0

My solution was to just launch the same project twice, in two different Visual Studio instances. Then you run your API (event multiple) in the first vidusl studio and then you run your tests in the second visual studio. Only downside is that files are getting locked, so you need to stop both test and api debug to modify and build changes.

Cockspur answered 7/6 at 6:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.