简体   繁体   English

如何在Visual Studio中的特定文件夹中运行单个测试或所有测试?

[英]How to run a single test or all tests in a specific folder in Visual Studio?

So I'm moving from Visual Studio 2015 with ReSharper to Visual Studio 2017 and I'm trying to remove ReSharper from my workflow. 因此,我将从使用ReSharper的Visual Studio 2015迁移到Visual Studio 2017,我正在尝试从我的工作流程中删除ReSharper。

I know what CTRL+R,T runs either a whole TestClass or all tests depending on where you run it. 我知道什么是CTRL + R,T运行整个TestClass或所有测试,具体取决于你运行它的位置。 It seems selecting something inside a single unit test still runs the whole test class. 似乎在单个单元测试中选择一些东西仍然运行整个测试类。

Is it possible to run a single unit test? 可以运行单个单元测试吗?

I'm also missing right-clicking a folder in solution explorer and running all the tests in it. 我也错过了右键单击解决方案资源管理器中的文件夹并运行其中的所有测试。

Is there an extension which provides this tiny feature? 有没有提供这个小功能的扩展?

CTRL+R, T is by defualt is assign to TestExplorer.RunAllTestsInContext . CTRL+R, T由defualt分配给TestExplorer.RunAllTestsInContext

TestExplorer.RunAllTestsInContext is works as the following based on the cursor: TestExplorer.RunAllTestsInContext基于游标如下所示:

在此输入图像描述

So it seems that TestExplorer.RunAllTestsInContext is what you are looking for... 所以似乎TestExplorer.RunAllTestsInContext就是你要找的......

To make sure what key may is assign to this feature click on Tools -> options -> Environment -> Keyboard , in the search bar write: TestExplorer.RunAllTestsInContext then you'll be able to see keymap/ set new one. 要确保分配给此功能的键,请单击Tools -> options -> Environment -> Keyboard ,在搜索栏中写入: TestExplorer.RunAllTestsInContext然后您将能够看到键映射/设置新键。

在此输入图像描述

I'm also missing right-clicking a folder in solution explorer and running all the tests in it. 我也错过了右键单击解决方案资源管理器中的文件夹并运行其中的所有测试。

Is there an extension which provides this tiny feature? 有没有提供这个小功能的扩展?

As I know there is no such a tool basically because folders don't have any restriction on code in C#. 据我所知,基本上没有这样的工具,因为文件夹对C#中的代码没有任何限制。 The correct way to do such a thing is to use ` TestCategory attribute . 执行此类操作的正确方法是使用` TestCategory属性

You can run a single unit test from the Tests Explorer window. 您可以从“ Tests Explorer窗口运行单个单元测试。 When you have done it once, you can rerun the last tests run using Ctrl+R, L . 完成一次后,可以使用Ctrl+R, L重新运行最后一次测试。 So if the last run you have done is a single unit test, it will be the only one to be rerun. 因此,如果您最后一次运行是单个单元测试,那么它将是唯一一个重新运行。 Sadly, it seems there is no shortcut to run the unit test under cursor. 可悲的是,似乎没有在光标下运行单元测试的捷径。

Regarding the other part of your question, with the Tests Explorer window you can have tests grouped by namespace, project, class or result and then run all tests of a specific group. 关于问题的其他部分,使用“ Tests Explorer窗口,您可以按命名空间,项目,类或结果分组测试,然后运行特定组的所有测试。 Maybe it can fit our needs? 也许它可以满足我们的需求?

Hope this help. 希望这有帮助。

In the TestExplorer you can group tests by Class (there is a Group By button in the toolbar as shown in the image) then it will group tests by their classes and you can right-click on a group an click Run Selected Tests . TestExplorer您可以按Class测试进行分组(工具栏中有一个Group By按钮,如图所示)然后它将按类对测试进行分组,您可以右键单击一个组,然后单击Run Selected Tests

在此输入图像描述

You can have a new filter criteria in the search box of test explorer . 您可以在test explorer的搜索框中使用新的过滤条件。 In the filter drop down , you can select a full name option and there you can give your namespace . 在过滤器下拉列表中,您可以选择全名选项,然后您可以在其中提供命名空间。

It will list entire test files located under that namespace. 它将列出位于该命名空间下的整个测试文件。 You can then select all of the test file and do "Run selected tests". 然后,您可以选择所有测试文件并执行“运行选定的测试”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio:在单个项目中运行所有测试? - Visual Studio: Run all tests in a single project? TeamCity Visual Studio测试构建步骤以运行单个测试 - TeamCity Visual Studio Tests build step to run single test 如何为项目中特定文件夹内特定类型的所有文件运行Visual Studio宏 - How Do I Run a Visual Studio Macro for All Files of a Certain Type Within a Specific Folder Within a Project 在Visual Studio中运行所有打开的测试 - Run all open tests in Visual Studio 如何在命令行中运行通常在Visual Studio测试资源管理器中运行的.cs测试? - How do I run .cs tests that I normally run in the Visual Studio Test Explorer, in the command line? Visual Studio测试资源管理器要求全部运行 - Visual Studio test explorer requirements run all 在Visual Studio中运行所有测试项目 - Run all test projects in Visual Studio 如何在 visual studio 2022 中运行 NUnit 2 测试 - How to run NUnit 2 tests in visual studio 2022 Visual Studio单元测试:在每次测试之前运行初始化代码 - Visual Studio Unit tests: run initialization code before each test 最大。 Visual Studio负载测试中的负载测试运行持续时间 - Max. Load Test Run Duration in Visual Studio Load Tests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM