这可能是Visual Studio for Mac中不存在的功能,但我想我可能会在这里询问我是否做错了。
我将ASP.NET Core MVC项目设置为启动项目。
我还有一组针对.NET Core 2.0的单元测试,它使用Selenium来驱动UI测试。为了运行这些测试,我需要先运行ASP.NET Core MVC才能运行测试,否则它们会因为应用程序没有运行而失败。
在Visual Studio的PC版本中,"开始无需调试" " Debug"中的选项菜单按预期启动Web应用程序。我的浏览器打开我的应用程序。一旦我确认它正在运行,我就可以毫无问题地运行测试(通过测试资源管理器)。
在Mac版的Visual Studio中,"开始时无需调试" " Debug"中的选项菜单按预期启动Web应用程序。我的浏览器打开我的应用程序。一旦我确认它正在运行,我就会尝试运行测试。测试确实在运行之前运行,它会杀死正在运行的应用程序进程。由于应用程序不再运行,测试失败。
TL; DR:
我的解决方案:
以下是VS的两个实例的步骤:
预期:测试通过PC和Mac版本
实际:Mac版测试失败,因为在运行测试之前Web应用程序进程被终止
有没有人对我如何实现我想要实现的目标有任何建议?
答案 0 :(得分:1)
Looking at the Visual Studio Mac source code there is a restriction that prevents this. Visual Studio for Mac keeps a track of all applications that it has run and when you try to run the unit test it will attempt to close these applications.
Testing this with Visual Studio for Mac 7.1 a message dialog is displayed An application is already running and will have to be stopped. Do you want to continue?
when you run the tests.
Without changing the code you can only workaround this.
Workarounds:
More detail about option 3. To create a run configuration right click the solution and select Options. Then in the Solution Options create a run configuration in the Run - Configurations section. Then select it and check the web project and unit test project. In the status bar you will need to your run configuration. This should work if you can run your unit test project in Visual Studio for Mac. A unit test project that uses NUnit can be set as the startup project and running it will run the tests.