简体   繁体   English

在VS2017中,是否有一种方法可以一次将所有失败的单元测试的名称复制到剪贴板?

[英]In VS2017, is there a way to copy the names of all the failed unit tests to the clipboard at one time?

It is not my decision personally to have lingering failing unit tests. 我个人的决定不是要让单元测试一直徘徊不前。

In the solution I work with at my company, there are a few failing unit tests that have lingered over time. 在我与公司合作的解决方案中,随着时间的流逝,有一些失败的单元测试持续存在。 Occasionally, while making changes, another unit test will start to fail, but it won't be clear which one it is. 有时,在进行更改时,另一个单元测试将开始失败,但是不清楚是哪个单元测试。 To figure it out, it's sometimes necessary to copy at least the names of the failing unit tests out into a text file and do a comparison. 为了弄清楚,有时必须至少将发生故障的单元测试的名称复制到文本文件中并进行比较。

In VS2017, in the Test Explorer, you can right-click a unit test and select Copy, and it will copy the name and some other meta-information to your clipboard. 在VS2017中,可以在“测试资源管理器”中右键单击单元测试,然后选择“复制”,它将名称和其他一些元信息复制到剪贴板。 However, if you select multiple unit tests, that option disappears. 但是,如果选择多个单元测试,该选项将消失。 Additionally there doesn't appear to be any "Copy All" option available. 此外,似乎没有任何“全部复制”选项可用。

So if you're needing to copy the names of all of the unit tests that are failing (other related meta-information is okay), is there a way to do this in Visual Studio 2017 other than manually copying the tests one at a time? 因此,如果您需要复制所有失败的单元测试的名称(其他相关的元信息也可以),除了每次手动复制一个测试之外,还有一种方法可以在Visual Studio 2017中做到这一点?

This is not a direct answer to your question, but rather a workaround (though I'd call it a best practice compared to what you seem to be doing): 这不是您问题的直接答案,而是一种解决方法(尽管与您似乎正在做的事情相比,我将其称为最佳实践):

You seem to have a number of unit tests that produce errors and for whatever reason you decided to not fix them in time. 您似乎有许多单元测试会产生错误,并且由于某种原因您决定不及时修复它们。 Fixing them would be the obvious solution, but lets assume there were reasons to not do so. 修复它们将是显而易见的解决方案,但请假设有理由不这样做。

Now everybody that develops a feature after that decision is in trouble, because the unit test result just became unreliable . 现在,在该决定后开发功能的每个人都陷入了麻烦,因为单元测试结果才变得不可靠 They might fail and you will never know if it's your error, or maybe that test was supposed to fail because of the former (bad) decision. 它们可能会失败,并且您将永远不知道这是否是您的错误,或者由于先前(错误的)决定,该测试应该失败了。 Failed tests have transformed from a red/green quality signal to a broken traffic light signaling nothing. 失败的测试已从红色/绿色质量信号变为故障信号灯,无任何信号。

You should mark those tests that fail on purpose so that you know which they are. 您应该标记那些故意失败的测试,以便知道它们是什么。 If you are using MSTest (the Visual Studio default) you can do so by annotating them with the [Ignore] attribute. 如果您使用的是MSTest(Visual Studio的默认设置),则可以使用[Ignore]属性对其进行注释。 That way, they will not be run, will not count as failed, but will still appear in the list and remind you of the fact that they still need to be fixed. 这样,它们将不会运行,也不会被视为失败,而是仍会出现在列表中,并提醒您仍然需要对其进行修复的事实。

That way, your tests are reliable again. 这样,您的测试将再次可靠。 Anything red is something you broke. 任何红色都是破坏的东西。 Anything red is something you need to fix. 任何红色都是您需要修复的东西。 Yellow are tests that were broken anyway and green.. well is green. 黄色是无论如何都被破坏的测试,而绿色则是绿色。

No need to compare lists of testnames against each other. 无需相互比较测试名称列表。 Use the means available. 使用可用的方法。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM