如何在调试Web项目的同时运行测试?

ami*_*t_g 19 asp.net visual-studio visual-studio-2012

在一些解决方案中,我们有ASP.NET/WCF Web项目和测试项目.一些测试针对ASP.NET开发Web服务器使用http://localhost:port/....在VS2010中,当ASP.NET/WCF Web项目正在调试时,测试运行器可以运行测试,如果Web项目中有任何断点,调试器将中断执行.这似乎已在VS2012中被禁用/删除.

调试ASP.NET/WCF Web项目(通过按F5或通过附加进程启动)时,将禁用TEST-> Run和TEST-> Debug子菜单.在VS2010中,只有Test-> Debug子菜单被禁用,而Test-> Run子菜单仍然启用.我们使用这种方式轻松调试Web项目中的服务.有什么方法可以恢复或解决这个问题?

在ASP.NET开发服务器运行时调试似乎不适用于VS2012,或者至少我无法使其工作.

Aro*_*ers 12

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.


Dir*_*aus 7

如果您有一个WCF应用程序和测试调用它们的解决方案,您可以通过调用Debug All TestsDebug Selected Tests来调试应用程序,而无需先前的Start Debugging(F5).

将解决方案配置为在所有操作中设置为None的多个启动项目,并将WCF应用程序配置为启动操作不要打开页面.等待请求.使用此配置,如果选择" 调试所有测试"或" 调试所选测试",则会启动开发Web服务器.


cro*_*sek 6

以下是调试单个单元测试和 Web 服务器的解决方法。它依赖于调试多个进程(不包括 MSVS Express):

  1. 启动 Web 服务器(非调试),记下其进程 ID(IIsExpress 图标 -> 显示所有应用程序)
  2. 在测试的第一行放置断点
  3. 开始调试单元测试,等待它在断点处停止。
  4. 调试 -> 连接到进程,输入 Web 服务器进程 ID

测试和服务器都在调试器中实时运行。


ami*_*t_g 3

我最终写了一个快速插件。事实证明,与VS2012一样,VS2012测试运行器也可以在Web项目调试时运行测试。只是菜单选项被禁用。