为什么场景大纲在 VS 2012 测试资源管理器中显示为“外部"? [英] Why are scenario outlines shown as 'External' in the VS 2012 Test Explorer?

查看:24
本文介绍了为什么场景大纲在 VS 2012 测试资源管理器中显示为“外部"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景大纲(又名场景模板),我希望使用 VS 2012 的测试资源管理器列出我的测试.默认的测试分组由项目"名称完成 - 如果我坚持下去,我的来自场景大纲的测试在外部"组中,而不是在我的项目组下.

I have a scenario outline (a.k.a scenario template) and I wish to list my tests using the VS 2012's Test Explorer. The default test grouping is done by the "Project" name - if I stick to it, my tests coming from scenario outlines are in the group "External" and not under the group of my project.

这是为什么?有解决方案吗?

Why is this and is there a solution/workaround to it?

我的情况是,我想使用测试资源管理器为给定项目运行所有测试.为所有这些设置相同的特征是愚蠢的,并且容易出现人为错误.

My scenario is that I'd like to run all of my tests for a given project using the Test Explorer. Setting the same trait for all of them is silly and prone to human mistakes.

我的解决方案有 10 个这样的项目,并且很快就会添加更多项目.因此,将项目的场景大纲测试保留在外部"下可能会导致任何人错过它们或获取属于另一个项目的场景大纲生成的测试.

My solution has 10 such projects with the idea of more being added to it soon. Thus keeping a project's scenario outlined tests under "External" may cause anyone to miss them or to grab a scenario outline-generated test that belongs to another project.

更新

GitHub 用户 Shashi (https://github.com/shashiprabhakar) 已向 SpecFlow 贡献者记录了一个问题:https://github.com/techtalk/SpecFlow/issues/275.非常感谢,伙计!我已经开始跟踪它,所以如果在那里提出了修复/解决方法,我会在这里发布它作为答案.

GitHub user Shashi (https://github.com/shashiprabhakar) has logged an issue to the SpecFlow contributors: https://github.com/techtalk/SpecFlow/issues/275. Thanks a lot, mate! I've started tracking it so if a fix/workaround is proposed there, I'll post it as an answer here.

推荐答案

<specFlow>
  <unitTestProvider name="..." /> <!-- this you have already -->
  <generator allowDebugGeneratedFiles="true" /> <!-- this is the important setting -->
</specFlow>

这是 Gaspar Nagy 在 App.config 文件中推荐的配置.allowDebugGeneratedFiles"似乎是一张票.关于标签及其子标签的更多信息可以在 官方 SpecFlow 配置页面上找到.不过,将其设置为 TRUE 只是第一步.

This is the configuration Gaspar Nagy has recommended in the App.config file. The "allowDebugGeneratedFiles" seems to be the one ticket. More info on the tag and it's sub-tags can be found on the official SpecFlow configurations page. Setting it to TRUE is only the first step though.

正如 Gaspar 所建议的,下一步是在解决方案资源管理器中右键单击项目文件并选择重新生成功能文件选项.

As Gaspar suggests, the next step is to right-click on the project file in the Solution Explorer and to select the Regenerate Feature Files option.

注意:当您设置 allowDebugGeneratedFiles 标志然后重新生成 .feature 文件时实际会发生什么,SpecFlow 只是删除了 #line hidden#line number 来自 .feature.cs 文件.

NB: What actually happens when you set the allowDebugGeneratedFiles flag and then regenerate the .feature files, SpecFlow simply removes the #line hidden and #line number from the .feature.cs file.

最后,我个人建议在重建之前或之后重新启动 Visual Studio 2012.当我尝试上述步骤时,只有在重新启动 Visual Studio 后,测试资源管理器才能正确显示测试.

Finally, I'd personally suggest to restart Visual Studio 2012 before or after rebuilding. When I tried the above steps, the Test Explorer showed the tests correctly only after restarting the Visual Studio.

PS:Gaspar 指出,如果 allowDebugGeneratedFiles 标志被提升 (=true),那么使用运行 SpecFlow 方案"选项将不再起作用.但是,我可以通过右键单击项目文件来使用该选项.甚至在我尝试 Gaspar 的建议之前,在 .feature 上使用该选项对我不起作用,所以这一定是他所指的缺点.

PS: Gaspar noted that if the allowDebugGeneratedFiles flag is raised (=true), then using the "Run SpecFlow Scenarios" option won't work anymore. However, I was able to use that option by right-clicking on the project file. Using that option on a .feature wasn't working for me even before I tried Gaspar's suggestion so that must be the drawback that he was referring to.

PS #2:Gaspar 还提到不会在 SpecFlow 1.9.2 中删除这样的缺点.

PS #2: Gaspar also mentions that there won't be such a drawback will be removed in SpecFlow 1.9.2.

这篇关于为什么场景大纲在 VS 2012 测试资源管理器中显示为“外部"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆