简体   繁体   English

在测试资源管理器中运行“全部运行”时是否可以排除测试项目

[英]Is it possible to exclude a Test Project when running 'Run All' in Test Explorer

I have some Specflow(3.9.40)-based UI test using Selenium Webdriver and NUnit(3.13.2) Framework.我使用 Selenium Webdriver 和 NUnit(3.13.2) 框架进行了一些基于 Specflow(3.9.40) 的 UI 测试。

I would like these tests to not run when I hit 'Run All' in the Test Explorer.当我在测试资源管理器中点击“全部运行”时,我希望这些测试不运行。

In my StepDefinition class I have tried adding the Explicit Attribute:在我的 StepDefinition class 我尝试添加显式属性:

[TestFixture, Explicit("Only run when called explicitly")]
[Binding]
public class LoginStepDefinitions
{ ...

, but for some reason it does not seem to work - The UI Tests still run. ,但由于某种原因,它似乎不起作用 - UI 测试仍在运行。

I imagine there may be something I can add to the [BeforeScenario] in my HookInitialization class, but I am stumped:我想我可以在我的 HookInitialization class 中添加一些内容到 [BeforeScenario] 中,但我很难过:

[BeforeScenario]
    public void FirstBeforeScenario()
    {
        var seleniumDriver = new SeleniumDriver(_scenarioContext);
        _scenarioContext.Set(seleniumDriver, "SeleniumDriver");
    }

Is there a way for me to tell Visual Studio Test Explorer to ignore the UI Tests or its folder?我有没有办法告诉 Visual Studio 测试资源管理器忽略 UI 测试或其文件夹?

The basic problem is that NUnit's Explicit setting is unique among the frameworks supported by Test Explorer, which knows nothing of this concept of "explicitness."基本问题是 NUnit 的Explicit设置在 Test Explorer 支持的框架中是独一无二的,它对“显式”这个概念一无所知。

If Test Explorer calls the NUnit adapter telling it to run all, then NUnit will honor the Explicit setting.如果测试资源管理器调用 NUnit 适配器告诉它运行所有,那么 NUnit 将遵循Explicit设置。 However, in some situations, it simply passes a list of all the tests to NUnit.但是,在某些情况下,它只是将所有测试的列表传递给 NUnit。 In that case, all tests appear (to NUnit) to have been run explicitly.在这种情况下,所有测试(对 NUnit 而言)似乎都已显式运行。

Which way Test Explorer calls NUnit is dependent on the version you are running and it's only possible to tell how it calls by debugging or by observing the outcome.测试资源管理器调用 NUnit 的方式取决于您正在运行的版本,只能通过调试或观察结果来判断它是如何调用的。 To add to the confusion, some versions of the NUnit3 adapter use heuristics to try to guess whether an explicit test was called explicitly.更令人困惑的是,某些版本的 NUnit3 适配器使用启发式方法来尝试猜测是否显式调用了显式测试。 This doesn't solve your problem but should make it easier to understand what is going on.这并不能解决您的问题,但应该更容易理解正在发生的事情。

The best workaround, if you are using TestExplorer, is to avoid Explicit and to set up categories, which control the running of the tests.如果您使用 TestExplorer,最好的解决方法是避免显式并设置控制测试运行的类别。 Fortunately, TestExplorer and NUnit have pretty much the same understanding of categories.幸运的是,TestExplorer 和 NUnit 对类别的理解几乎相同。

You can filter tests first in Test Explorer , then the "Run All" button is scoped to only those tests in the Test Explorer panel.您可以先在 Test Explorer 中过滤测试,然后“Run All”按钮的范围仅限于 Test Explorer 面板中的那些测试。 If you desire to run all tests except those in a certain project, enter this into the test filter search box in the Test Explorer panel:如果您希望运行除某个项目中的测试之外的所有测试,请在“测试资源管理器”面板的测试过滤器搜索框中输入:

-project:NameOfTheTestProject

If your test project has space characters in the name:如果您的测试项目名称中有空格字符:

-project:"Name of the test project"

Note the - character before the word project .请注意单词project之前的-字符。 This is crucial.这是至关重要的。 This character tells Visual Studio Test Explorer to invert your filter criteria — it is used to exclude tests in a certain project.此字符告诉 Visual Studio 测试资源管理器反转您的筛选条件 - 它用于排除某个项目中的测试。

If you have these UI tests intermingled with other kinds of tests, obviously filtering out an entire project is not desirable.如果您将这些 UI 测试与其他类型的测试混合在一起,那么显然过滤掉整个项目是不可取的。 Consider placing the UI tests in a specific folder and filter on the FullName instead.考虑将 UI 测试放在特定文件夹中,并改为在FullName上进行过滤。 For example, if your SpecFlow tests exist in a folder called "Specs", then omit those tests using:例如,如果您的 SpecFlow 测试存在于名为“Specs”的文件夹中,则使用以下命令省略这些测试:

-FullName:Specs

Again, include the - character (with no spaces) before the FUllName criteria to exclude tests in that namespace.再次,在FUllName标准之前包含-字符(不带空格)以排除该命名空间中的测试。 This works with SpecFlow because the namespaces for C# classes generated from .feature files follow the folder structure of your test project, just like adding a .cs file does.这适用于 SpecFlow,因为从.feature文件生成的 C# 类的命名空间遵循测试项目的文件夹结构,就像添加.cs文件一样。

This technique should work with any unit test provider, not just NUnit.这种技术应该适用于任何单元测试提供者,而不仅仅是 NUnit。

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

相关问题 在“测试资源管理器”中选择“全部运行”时,自动构建测试项目 - Build test project automatically when selecting Run All in Test Explorer Visual Studio:从测试资源管理器运行测试时默认排除项目 - Visual Studio: Exclude Project by default when running tests from test explorer Visual Studio 测试资源管理器无法在已编译的测试项目中运行测试 - Visual Studio Test Explorer cannot run tests in compiled test project 为什么在我构建项目时Visual Studio没有在Test Explorer中给我测试? - Why Does Visual Studio not give me a test in Test explorer when I build my project? 在测试项目中运行所有测试时管理Application.Current - Manage Application.Current while all tests are running in Test Project Xunit 测试测试资源管理器未运行测试 - Xunit testing test explorer not running tests 测试资源管理器 (VS) 显示 &#39;<Unknown project> &#39; - Test Explorer (VS) shows '<Unknown project>' 我如何在我要测试的本地项目中同时运行已运行的编码UI测试 - How can i run a Coded UI Test running at the same time the project in localhost that i want to test 为什么我的测试项目没有出现在测试资源管理器上 - why my test project doesn't appear on test explorer 可以在测试运行期间获得先前的测试 - Possible to get previous test during test run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM