如何让 VS2010 识别 SpecFlow 生成的 mstest?

发布于 2024-09-14 05:55:33 字数 802 浏览 2 评论 0 原文

我已将 Specflow 配置为以 MsTest 框架(而不是 NUnit)为目标,方法是在“specs”类库的 app.config 中指定它:

<configSections>
    <section name="specFlow"
   type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
</configSections>

<specFlow>
 <unitTestProvider name="MsTest.2010" />
</specFlow>

因此,一旦就位,我可以看到我的测试装置是由Specflow 自定义工具,具有正确的 TestClassAttribute() 和方法等:

[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.3.3.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()]
...

规范类已构建,但现在我无法使用 Test --> 运行测试运行-->我的 vista 64 机器上的 Visual Studio 2010 内的解决方案中的所有测试。为什么 VS 不将这些识别为要运行的有效测试?

I have configured Specflow to target the MsTest framework (instead of NUnit) by specifying it like this in the app.config of my 'specs' class library:

<configSections>
    <section name="specFlow"
   type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
</configSections>

<specFlow>
 <unitTestProvider name="MsTest.2010" />
</specFlow>

So once it's in place, I can see that my test fixtures are produced correctly by the Specflow custom tool, with correct TestClassAttribute() and methods, etc:

[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.3.3.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()]
...

The specs class builds, but now I cannot run the tests using the Test --> Run --> All Tests in Solution inside Visual Studio 2010 on my vista 64 box. Why doesn't VS recognize these as valid tests to run?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨落星ぅ辰 2024-09-21 05:55:33

根据 Dror HelperAlex Duggleby 您需要将以下行添加到 .csproj 文件中:

<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

将其添加到 FileAlignment 元素之后,然后重新加载项目。它现在应该是一个 MS Test 项目,并且您可以在此项目的上下文中获得 MS Test 功能。指南的意思是:

  • {3AC096D0-A1C2-E12C-1390-A8335801FDAB} - 测试项目
  • {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - C# 类库

As per Dror Helper and Alex Duggleby you'll want to add the following line to your .csproj file:

<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

Add it after the FileAlignment element, and reload the project. It should now be an MS Test project and you get the MS Test functionality in the context of this project. The Guids mean:

  • {3AC096D0-A1C2-E12C-1390-A8335801FDAB} - Test Project
  • {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - C# Class Library
白首有我共你 2024-09-21 05:55:33

我必须将项目重新创建为测试项目,而不仅仅是类库——因为我已经开始使用 NUnit 和 SpecFlow 进行开发,所以我创建了一个普通类库来保存我的规范,其中装饰了 NUnit 属性。我以为我可以简单地更改此现有项目的 app.config 以指向 mstest 框架并停止使用 NUnit,但 VS2010 从未识别出这些测试,尽管 Specflow 的自定义工具正确创建了存根。

所以...我在我的解决方案中添加了一个新的测试项目,将所有规范代码移至该新项目,然后重新编译,并且 viola、VS2010 识别了测试。我确信它正在 .csproj 文件的 XML 中寻找 GUID,或者告诉它连接测试框架的东西,但我没有深入研究。

希望这对某人有帮助。

I had to recreate the project as a Test Project and not merely a Class Library -- because I had started development with NUnit and SpecFlow, I had created a vanilla class library to hold my specs that had the NUnit attributes decorated. I thought I could simply change the app.config of this existing project to point at the mstest framework and stop using NUnit, but VS2010 never recognized the tests, despite the correct creation of the stubs by specflow's custom tool.

So...I added a new Test Project to my solution, moved all of my spec code to that new project, then recompiled, and viola, VS2010 recognizes the tests. I'm sure there is a GUID it is looking for in the XML of the .csproj file or something that tells it to wire up the testing framework, but I didn't dig that far.

Hope this helps someone.

垂暮老矣 2024-09-21 05:55:33

要将类库项目模板更改为测试项目,请修改 .csproj 并将以下行添加

<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

到第一个属性组元素:

<PropertyGroup>
    <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

To change your class library project template into a test project, modify the .csproj and add the following line:

<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

to the first property group element:

<PropertyGroup>
    <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文